Доброго времени суток... Столкнулся с такой проблемой: пытаюсь добавить в минимальный проект веб-приложения в NetBeans поддержку Hibernate, создал одну сущность, а так же класс для доступа к EntityManager: Код | import interfaces.factoryes.IPersistenceFactory; import javax.ejb.Singleton; import javax.persistence.EntityManager; import javax.persistence.Persistence; import javax.persistence.PersistenceContext;
@Singleton public class PersistenceFactory implements IPersistenceFactory {
@PersistenceContext(unitName = "jfrmPU") private EntityManager entityManager;
public PersistenceFactory() { this.entityManager = Persistence.createEntityManagerFactory("jfrmPU").createEntityManager(); }
public EntityManager getEntityManager() { return this.entityManager; } }
|
Дабы протестировать его работу, сделал тестовый сервлет, где просто создал объект этого класса, в результате чего в логах появилось: До перехода на /jfrm/Test: Код | INFO: closing INFO: PWC1412: WebModule[/jfrm] ServletContext.log():Destroying Spring FrameworkServlet 'dispatcher' INFO: Closing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sat Mar 20 01:32:15 KRAT 2010]; parent: Root WebApplicationContext INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@353df6aa: defining beans [org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping#0,urlMapping,viewResolver,indexController]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@35d7266e INFO: PWC1412: WebModule[/jfrm] ServletContext.log():Closing Spring root WebApplicationContext INFO: Closing Root WebApplicationContext: startup date [Sat Mar 20 01:32:13 KRAT 2010]; root of context hierarchy INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@35d7266e: defining beans []; root of factory hierarchy INFO: Hibernate Annotations 3.3.1.GA INFO: Hibernate 3.2.5 INFO: hibernate.properties not found INFO: Bytecode provider name : cglib INFO: using JDK 1.4 java.sql.Timestamp handling INFO: Hibernate EntityManager 3.3.2.GA INFO: Processing PersistenceUnitInfo [ name: jfrmPU ...] INFO: Binding entity from annotated class: entityes.JfrmUser INFO: Bind entity entityes.JfrmUser on table JfrmUser INFO: Hibernate Validator not found: ignoring INFO: Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider INFO: Using provided datasource INFO: RDBMS: MySQL, version: 5.1.43-community INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} ) INFO: Using dialect: org.hibernate.dialect.MySQLDialect INFO: Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory INFO: instantiating TransactionManagerLookup: org.hibernate.transaction.SunONETransactionManagerLookup INFO: instantiated TransactionManagerLookup INFO: Automatic flush during beforeCompletion(): disabled INFO: Automatic session close at end of transaction: disabled INFO: JDBC batch size: 15 INFO: JDBC batch updates for versioned data: disabled INFO: Scrollable result sets: enabled INFO: JDBC3 getGeneratedKeys(): enabled INFO: Connection release mode: auto INFO: Maximum outer join fetch depth: 2 INFO: Default batch fetch size: 1 INFO: Generate SQL with comments: disabled INFO: Order SQL updates by primary key: disabled INFO: Order SQL inserts for batching: disabled INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory INFO: Using ASTQueryTranslatorFactory INFO: Query language substitutions: {} INFO: JPA-QL strict compliance: enabled INFO: Second-level cache: enabled INFO: Query cache: disabled INFO: Cache provider: org.hibernate.cache.NoCacheProvider INFO: Optimize cache for minimal puts: disabled INFO: Structured second-level cache entries: disabled INFO: Statistics: disabled INFO: Deleted entity synthetic identifier rollback: disabled INFO: Default entity-mode: pojo INFO: Named query checking : enabled INFO: building session factory INFO: Not binding factory to JNDI, no JNDI name configured INFO: Running hbm2ddl schema update INFO: fetching database metadata INFO: updating schema INFO: table found: jfrm.jfrmuser INFO: columns: [id] INFO: foreign keys: [] INFO: indexes: [primary] INFO: schema update complete INFO: JNDI InitialContext properties:{} INFO: Portable JNDI names for EJB PersistenceFactory : [java:global/jfrm/PersistenceFactory, java:global/jfrm/PersistenceFactory!interfaces.factoryes.IPersistenceFactory] INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver. INFO: nullID: /D:/proj/4_kurs/jfrm/jfrm/build/web/ CLASSES: [class entityes.JfrmUser, class impls.factoryes.PersistenceFactory, interface interfaces.factoryes.IPersistenceFactory, class test.Test]
INFO: PWC1412: WebModule[/jfrm] ServletContext.log():Initializing Spring root WebApplicationContext INFO: Root WebApplicationContext: initialization started INFO: Refreshing Root WebApplicationContext: startup date [Sat Mar 20 01:33:29 KRAT 2010]; root of context hierarchy INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml] INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3b8b0614: defining beans []; root of factory hierarchy INFO: Root WebApplicationContext: initialization completed in 1293 ms INFO: PWC1412: WebModule[/jfrm] ServletContext.log():Initializing Spring FrameworkServlet 'dispatcher' INFO: FrameworkServlet 'dispatcher': initialization started INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sat Mar 20 01:33:31 KRAT 2010]; parent: Root WebApplicationContext INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@309e1550: defining beans [org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping#0,urlMapping,viewResolver,indexController]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@3b8b0614 INFO: Mapped URL path [/index.html] onto handler [org.springframework.web.servlet.mvc.ParameterizableViewController@3d7c869c] INFO: FrameworkServlet 'dispatcher': initialization completed in 2185 ms INFO: Loading application jfrm at /jfrm INFO: jfrm was successfully deployed in 22 237 milliseconds.
|
После перехода на /jfrm/Test: Код | INFO: Binding entity from annotated class: entityes.JfrmUser INFO: Bind entity entityes.JfrmUser on table JfrmUser INFO: Hibernate Validator not found: ignoring INFO: JNDI InitialContext properties:{} INFO: Using datasource: jfrm INFO: RDBMS: MySQL, version: 5.1.43-community INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} ) INFO: Using dialect: org.hibernate.dialect.MySQLDialect INFO: Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) INFO: Automatic flush during beforeCompletion(): disabled INFO: Automatic session close at end of transaction: disabled INFO: JDBC batch size: 15 INFO: JDBC batch updates for versioned data: disabled INFO: Scrollable result sets: enabled INFO: JDBC3 getGeneratedKeys(): enabled INFO: Connection release mode: auto INFO: Maximum outer join fetch depth: 2 INFO: Default batch fetch size: 1 INFO: Generate SQL with comments: disabled INFO: Order SQL updates by primary key: disabled INFO: Order SQL inserts for batching: disabled INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory INFO: Using ASTQueryTranslatorFactory INFO: Query language substitutions: {} INFO: JPA-QL strict compliance: enabled INFO: Second-level cache: enabled INFO: Query cache: disabled INFO: Cache provider: org.hibernate.cache.NoCacheProvider INFO: Optimize cache for minimal puts: disabled INFO: Structured second-level cache entries: disabled INFO: Statistics: disabled INFO: Deleted entity synthetic identifier rollback: disabled INFO: Default entity-mode: pojo INFO: Named query checking : enabled INFO: building session factory INFO: Not binding factory to JNDI, no JNDI name configured INFO: Running hbm2ddl schema update INFO: fetching database metadata INFO: updating schema INFO: table found: jfrm.jfrmuser INFO: columns: [id] INFO: foreign keys: [] INFO: indexes: [primary] INFO: schema update complete WARNING: StandardWrapperValve[Test]: PWC1406: Servlet.service() for servlet Test threw exception javax.persistence.PersistenceException: [PersistenceUnit: jfrmPU] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) at impls.factoryes.PersistenceFactory.<init>(PersistenceFactory.java:20) at test.Test.processRequest(Test.java:29) at test.Test.doGet(Test.java:58) at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
|
Хотя сразу после деплоя в базе создается таблица для созданной сущности... Подскажите, плс, чего я делаю неправильно...
|