我是休眠世界的新手,正在准备一个演示样本。我尝试使用 entityManager.persist(entity) 功能。没有错误,但实体没有持久化到数据库中。
这是我的 persistence.xml 文件...
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="NCLPEntity">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!--
<jta-data-source>nclp/oracle</jta-data-source>
-->
<class>com.fks.nclp.model.MapRoleModule</class>
<class>com.fks.nclp.model.MstCityDtl</class>
<class>com.fks.nclp.model.MstClpMcDtl</class>
<class>com.fks.nclp.model.MstDiscSlbDtl</class>
<class>com.fks.nclp.model.MstFormatDtl</class>
<class>com.fks.nclp.model.MstGeneralDtl</class>
<class>com.fks.nclp.model.MstMediaType</class>
<class>com.fks.nclp.model.MstModuleDtl</class>
<class>com.fks.nclp.model.MstRoleDtl</class>
<class>com.fks.nclp.model.MstSiteDtl</class>
<class>com.fks.nclp.model.MstStateDtl</class>
<class>com.fks.nclp.model.MstUserDtl</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@10.0.7.62:1521:CLP"/>
<property name="hibernate.default_schema" value="clp_orcl_db"/>
<property name="hibernate.connection.username" value="CLPREM"/>
<property name="hibernate.connection.password" value="********"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.query.factory_class" value="org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="false"/>
<property name="hibernate.order_inserts" value="true"/>
<property name="hibernate.order_updates" value="true"/>
<property name="hibernate.jdbc.batch_size" value = "30" />
</properties>
</persistence-unit>
</persistence>
这是我正在测试持久功能的存根...
package com.fks.nclp.junit;
import java.math.BigDecimal;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import com.fks.nclp.model.MstStateDtl;
public class Test_1 {
public static void main(String a[]){
EntityManagerFactory emf = Persistence.createEntityManagerFactory("NCLPEntity");
EntityManager em = emf.createEntityManager();
MstStateDtl state = new MstStateDtl();
state.setStateId(1002);
state.setZoneId(new BigDecimal("1234"));
state.setDescription("testing");
em.persist(state);
em.close();
emf.close();
}
}
这是控制台输出...
May 22, 2012 5:43:40 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
May 22, 2012 5:43:40 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.1}
May 22, 2012 5:43:40 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
May 22, 2012 5:43:40 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
May 22, 2012 5:43:41 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
May 22, 2012 5:43:41 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
May 22, 2012 5:43:41 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
May 22, 2012 5:43:41 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@10.0.7.62:1521:CLP]
May 22, 2012 5:43:41 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=CLPREM, password=****, autocommit=true, release_mode=auto}
May 22, 2012 5:43:42 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
May 22, 2012 5:43:42 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
May 22, 2012 5:43:42 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
May 22, 2012 5:43:42 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
May 22, 2012 5:43:42 PM org.hibernate.validator.util.Version <clinit>
INFO: Hibernate Validator 4.1.0.Final
May 22, 2012 5:43:42 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
May 22, 2012 5:43:42 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
May 22, 2012 5:43:43 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:oracle:thin:@10.0.7.62:1521:CLP]
萨克斯,贡詹。