3

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!

matino
  • 17,199
  • 8
  • 49
  • 58
Pankaj
  • 229
  • 3
  • 7
  • Did you check if its the correct session instance that you are using? – Pratik Shelar Oct 01 '13 at 06:21
  • Can you explain what you meant by correct session instance? There's only one variable(pojoSession) in the method, from which I am trying to get a dynamic session. – Pankaj Oct 01 '13 at 06:27
  • Mostly these kind of exceptions occur when you import the Session object of some different package. Make sure you have imported org.hibernate.Session – Pratik Shelar Oct 01 '13 at 06:30
  • Verified, the session instance I am using is instantiated from org.hibernate.Session. – Pankaj Oct 01 '13 at 06:34

2 Answers2

0

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.

Gaurav
  • 1,549
  • 2
  • 15
  • 31
  • Tried from command line, still same error. "[ERROR] symbol : method getSession(org.hibernate.EntityMode)" – Pankaj Oct 01 '13 at 07:25
  • There is no Session.getSession(EntityMode entityMode) in Hibernate 4. Check this link http://docs.jboss.org/hibernate/orm/4.2/javadocs/index.html?org/hibernate/Session.html – Gaurav Oct 01 '13 at 08:17
0

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.

Gaurav
  • 1,549
  • 2
  • 15
  • 31
  • Gaurav, though I agree with you, what is confusing me is this link "https://hibernate.atlassian.net/browse/HHH-7714". The URL you posted was updated in Jan, where as seems like Brad Koehn has added a patch to 4.2.1/4.3.0Beta for same requirement in July 2013. Not sure whether that patch has been ported to Jboss Maven Repository or not. If not, can someone assist me on how can I use the patch with hibernate 4.2. – Pankaj Oct 01 '13 at 08:41