Domanda

I am new to JPA . Earlier I know Hibernate. But as per the requirement, I need to enhance to Hibernate+JPA Configuration.

Please Look my configuration.

POJO:

package com.skc.order;

import javax.annotation.Generated;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="blc_order")
public class Orders {
    @Id
    @Column(name="order_id")
    Long orderId;

    @Column(name="ORDER_NUMBER")
    String orderNumber;

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }


}

Persistance.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="ExpensePersistentUnit"  transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>tamSql</non-jta-data-source>
        <class>com.skc.order.Orders</class>
        <properties>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/broadleaf" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"></property>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.connection.password" value="root" />
            <property name="hibernate.connection.username" value="mysql" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="true" />
        </properties>
    </persistence-unit>

EntityManagerTest Class :

package com.skc.order;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

public class EntityManagerTest {
    /*@PersistenceContext(unitName = "ExpensePersistentUnit")
    protected EntityManager em;*/

    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("ExpensePersistentUnit");
        EntityManager em = emf.createEntityManager();
        Query qry = em.createNativeQuery("select * from blc_order", Orders.class);
        Orders order = em.find(Orders.class, 1512);
        System.out.println(order.getOrderNumber());
    }
}

Jar Added In the ClassPath :

antlr-2.7.7
dom4j-1.6.1 
hibernate-commons-annotations-4.0.1.Final
hibernate-core-4.2.0.Final
hibernate-jpa-2.0-api-1.0.1.Final 
hibernate-validator-4.3.1.Final
javassist-3.15.0-GA
jboss-logging-3.1.2.GA
jboss-logmanager-1.4.0.Final
jboss-transaction-api_1.1_spec-1.0.1.Final
log4j-jboss-logmanager-1.0.1.Final
slf4j-api-1.6.1
slf4j-log4j12-1.6.1
commons-logging-1.1.1
hibernate-3.2.3.ga
hibernate-entitymanager-3.3.2.GA

And I am getting exception like :

Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.hibernate.cfg.Configuration.<init>(Lorg/hibernate/cfg/SettingsFactory;)V from class org.hibernate.ejb.Ejb3Configuration
    at org.hibernate.ejb.Ejb3Configuration.<init>(Ejb3Configuration.java:134)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:124)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at com.skc.order.EntityManagerTest.main(EntityManagerTest.java:13)

Please Help me out to solve this Problem. Thanks ...

È stato utile?

Soluzione

For Hibernate-core use 3.6.3 version..

This error used to come due to the class version mismatch. So I also got the same error just few minutes back. I just changed the version and that error is gone now. I am using hibernate core 3.6.3.FINAL with spring version 4.1.7.RELEASE. Hope this will work for you too. If you have doubt please comment.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top