0

I'm new with Hibernate 4.3 and need initialize the instances of the entities. With hibernate 3 I used the Hibernate.initialize() but in the version 4.3 the don't found the command neither the import org.hibernate.Hibernate.

I used the Eclipse Kepler and Wildfly 8.0.

can tell me how to do this?

Thanks

enter image description here enter image description here

Tunaki
  • 116,530
  • 39
  • 281
  • 370
Jericob
  • 1,607
  • 2
  • 12
  • 14

2 Answers2

2

Issue is with classpath only that you are not able to see the imports correctly, also i would recommend to use the below code snippet for intializing proxies.

Create a class HibernateUtils and call it's static method.

public class HibernateUtils {

    public static <T> T initializeAndUnproxy (T entity) {
        if (entity == null) {
            return null;
        }

        if (entity instanceof HibernateProxy) {
            entity = (T) ((HibernateProxy) entity).getHibernateLazyInitializer().getImplementation();
        }

        return entity;
    }


}
Ankur Singhal
  • 23,626
  • 10
  • 70
  • 108
  • what is the difference with the next solution? [hibernate]http://stackoverflow.com/questions/2216547/converting-hibernate-proxy-to-real-object this use hibernate.intialize – Jericob Jul 11 '14 at 15:11
  • @Jericob Yeah almost same thing, but the above code snippet is from my project code. – Ankur Singhal Jul 11 '14 at 16:57
0

Things to consider :

Have you include hibernate jar files (especially the required jars) in your lib folder ?

antlr-2.7.7.jar
commons-collections-3.2.1.jar
dom4j-1.6.1.jar
javassist-3.12.1.GA.jar
hibernate-core-4.0.1.Final.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
jboss-logging-3.1.0.CR2.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar

this file is from hibernate you will download and it will have required folder inside lib.

If yes :

Right click the import which contains error , and click Fix project setup and missing jar files will be automatically included.

bumbumpaw
  • 2,338
  • 1
  • 16
  • 49