Konfiguracja Hibernate i persitance.xml

0

Część
Mam problem z budowaniem aplikacji restowej prze ustawienia JPA. Co mam źle bo już nie mam pomysłów

persistance.xml

<persistence 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"
             version="2.0">
    <persistence-unit name="sample">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>com.test.model.Employee</class>
        <properties>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"></property>
            <property name="hibernate.connection.password" value="haslo"></property>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/db"></property>
            <property name="hibernate.connection.username" value="root"></property>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"></property>
        </properties>
    </persistence-unit>
</persistence>

hiebrnate

<?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="connection.url">jdbc:mysql://localhost:3306/xxx</property>
        <property name="connection.username">root</property>
        <property name="connection.password">xxx</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
 
        <property name="show_sql">true</property>
 
        <property name="format_sql">true</property>
        <property name="hbm2ddl.auto">create-drop</property>
 
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
        <property name="current_session_context_class">thread</property>
 
        <mapping class="com.test.model.Employee" />
 
    </session-factory>
</hibernate-configuration>
0

Błędem jest to że stosuje:

@PersistenceContext
EntityManager em;

Caused by: java.lang.IllegalArgumentException: WFLYWELD0037: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named '' in deployment test.war for injection point javax.persistence.EntityManager com.test.controller.LoginController.em"}}

Ale nadal nie wiem dla czego to się dzieje???

0

Dlaczego do konfiguracji nie użyjesz adnotacji?

0

@insectoman możesz mi napisać jak to zrobić?

0

mv persistance.xml persistence.xml

0

haha. Dziękuje

1 użytkowników online, w tym zalogowanych: 0, gości: 1