У меня большая проблема с базовым Hibernate во всех моих проектах.
У меня есть сервер MySQL, и есть база данных hiber (localhost).
Есть две таблицы: сообщения и пользователь .
У меня Glassfish 3.1 .
Я начал новый проект в Netbeans 7 с Hibernate Framework .
Затем я создал сущности и файл persistence.xml, PersistenceUnit.
После этого я создал сервлет, т.е.Демо (отображается как / Демо).
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Demo</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Demo at " + request.getContextPath () + "</h1>");
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("WebApplication7PU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Message m = new Message(Integer.SIZE, 0, "Hello world");
em.persist(m);
em.getTransaction().commit();
out.println("</body>");
out.println("</html>");
}
catch (Exception ex){
out.println("error: "+ex.getMessage());
}
finally {
out.close();
}
}
Когда я запустил свое WebApp, я увидел проблему с EntityManagerFactory:
Ошибка: [PersistenceUnit: WebApplication7PU] Невозможно построить EntityManagerFactory
В чем проблема?Я не могу это исправить: (
.
. - ДОПОЛНИТЕЛЬНАЯ ИНФОРМАЦИЯ -
Это видео на YouTube с моей проблемой.
.
.
.
Центр обновлений Glassfish:
Существуют такие пакеты, как JPA и Hibernate.
Журнал Glassfish:
INFO: Hibernate Validator not found: ignoring
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: JNDI InitialContext properties:{}
INFO: Using datasource: hiberMysql
INFO: RDBMS: MySQL, version: 5.1.53-community-log
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.13 ( Revision: ${bzr.revision-id} )
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
INFO: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
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 region factory : org.hibernate.cache.impl.NoCachingRegionFactory
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: Check Nullability in Core (should be disabled when Bean Validation is on): disabled
INFO: building session factory
INFO: Not binding factory to JNDI, no JNDI name configured
Persistnce.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="WebApplication7PU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>hiberMysql</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hiber</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">haslo</property>
</session-factory>
</hibernate-configuration>