问题
I am trying to use dynamic hibernate model, below is the code snippet to get the session.I have declared "hibernate.default_entity_mode" as "dynamic_map" in hibernate session factory config xml.
// Declared at class level
@Autowired
private SessionFactory sessionFactory;
//In specific java-method
Session pojoSession = sessionFactory.getCurrentSession();
Session ds = pojoSession.getSession(EntityMode.MAP);
Still, I get an exception in eclipse saying-"The method getSession(EntityMode) is undefined for the type Session" on second line, while trying to get dynamicSession from pojoSession.
I am using Hibernate 4.2.6.Final core and entity-manager & spring 3.2 framework jars.
Can anyone assist on what I am doing wrong?
Update: Seems like that method is actually missing from 4.2.6 org.hibernate.Session class. Also, checked earlier versions 4.2.1, 4.2.3 etc, but don't see any getSession() method defined for Session class. Not sure if the feature has been removed. Can anyone assist on what is the latest version of hibernate supporting EntityMode.MAP?
Thanks!
回答1:
The eclipse error might be misleading if you have wrong hibernate library in eclipse project. Check the version of hibernate in eclipse project and if you are using maven then compile using maven from command line.
回答2:
Pankaj, I think hibernate had complete removed setting of entity mode programmatically. The only way is to have a separate session factory with entity mode configured in configuration file.
来源:https://stackoverflow.com/questions/19109319/entitymode-map-with-hibernate-4-2-6-spring-3-2