私は休止状態の初心者です。最近、Hibernate を学び始めました。私はチュートリアルに従っています...しかし、私は今迷っています。私はこの問題を解決しようとしてきました...
hibernate.cfg.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"
>
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect" >
org.hibernate.dialect.SQLServer2008Dialect
</property>
<property name="hibernate.connection.driver_class" >
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="hibernate.connection.username" >
not required
</property>
<property name="hibernate.connection.password" />
<property name="hibernate.connection.url" >
jdbc:sqlserver://localhost;databaseName=hibernate;integratedSecurity=false;
</property>
<property name="hibernate.cache.use_query_cache" >
true
</property>
<property name="hibernate.cache.region_prefix" >
hibernate.test
</property>
<property name="hibernate.jdbc.use_streams_for_binary" >
true
</property>
<property name="hibernate.jdbc.batch_size" >
0
</property>
<property name="hibernate.max_fetch_depth" >
3
</property>
<property name="hibernate.hbm2ddl.auto" >
create-drop
</property>
<property name="hibernate.generate_statistics" >
true
</property>
<property name="hibernate.cache.region.factory_class" >
org.hibernate.testing.cache.CachingRegionFactory
</property>
<mapping class="com.hibernate.dto.UserDetails" />
<class-cache
class="org.hibernate.ejb.test.item"
usage="read-write" />
<collection-cache
collection="org.hibernate.ejb.test.Item.distributors"
region="RegionName"
usage="read-write" />
<event type="pre-insert" />
</session-factory>
</hibernate-configuration>
UseDetails.java
package com.hibernate.dto;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class UserDetails {
@Id
private int userId;
private String userName;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
hibernateTest.java
package com.hibernate.dto;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
public class HibernateTest {
public static void main(String[] args) {
UserDetails user = new UserDetails();
user.setUserId(1);
user.setUserName("ahmed");
SessionFactory sessionfact = new Configuration().configure()
.buildSessionFactory();
Session session = sessionfact.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
session.close();
}
}
今私がそれを実行しようとすると。毎回次のエラーが表示されます...しかし、それが何を指しているのかまだわかりませんか? 私を助けてください...
エラーログ
Aug 25, 2012 10:27:40 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Aug 25, 2012 10:27:40 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.6.Final}
Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Exception in thread "main" org.hibernate.MappingException: Cannot cache an unknown entity: org.hibernate.ejb
at org.hibernate.cfg.Configuration.applyCacheConcurrencyStrategy(Configuration.java:2212)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1368)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1733)
at com.hibernate.dto.HibernateTest.main(HibernateTest.java:25)
休止状態の瓶を調べましたが、見つかりませんでしたorg.hibernate.ejb.test.item
アップデート
今、私はこれらのエラーを受け取ります
Aug 25, 2012 11:51:06 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Aug 25, 2012 11:51:06 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.6.Final}
Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Aug 25, 2012 11:51:06 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Aug 25, 2012 11:51:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Aug 25, 2012 11:51:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Aug 25, 2012 11:51:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost;databaseName=hibernate;integratedSecurity=false;]
Aug 25, 2012 11:51:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=not required, password=****}
Aug 25, 2012 11:51:07 PM com.microsoft.sqlserver.jdbc.SQLServerConnection <init>
SEVERE: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
Aug 25, 2012 11:51:07 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
Aug 25, 2012 11:51:07 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Aug 25, 2012 11:51:07 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Aug 25, 2012 11:51:07 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Exception in thread "main" org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.testing.cache.CachingRegionFactory]
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:410)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:264)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2279)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2275)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784)
at com.hibernate.dto.HibernateTest.main(HibernateTest.java:21)
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.testing.cache.CachingRegionFactory]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141)
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:393)
... 6 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.testing.cache.CachingRegionFactory
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
... 7 more
@Table (name = "hibernate")
私も一緒に追加し@Entity
ました。