Hibernate mappings - how do JAVA classes recognize it

This is a discussion on Hibernate mappings - how do JAVA classes recognize it within the J2EE forums in Framework and Interface Programming category; I have a java class that has two methods private void populatePreceedingVarVerHashMap(int varVerId, Session session,Map map) { String sql = "from DbProcess d where d.varVer.id=? and d.schma='eV12'"; Object[] params = new Object[1]; params[0] = new Integer(varVerId); DbProcess dbProcess = (DbProcess) hUtil.executeQueryReturnUniqueResult(session, sql, params); if(dbProcess != null){ int val = dbProcess.getVal(); map.put(new Integer(varVerId),new Integer(val)); populatePreceedingVarVerHashMap(val,session,map); } } private void clearExistingVarVerChgLog(int varVerId,Session session){ String sql = "delete from VarVerChgLog v where v.varVer.id=?"; Query q = session.createQuery(sql); q.setInteger(0,varVerId); q.executeUpdate(); } While the query in the second method ' String sql = "delete from VarVerChgLog v where v.varVer.id=?";' is recoginzed by IntelliJ as a ...

Go Back   Application Development Forum > Framework and Interface Programming > J2EE

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 02-29-2008, 01:40 PM
ranjana14
Guest
 
Default Hibernate mappings - how do JAVA classes recognize it

I have a java class that has two methods

private void populatePreceedingVarVerHashMap(int varVerId, Session session,Map map) {
String sql = "from DbProcess d where d.varVer.id=? and d.schma='eV12'";
Object[] params = new Object[1];
params[0] = new Integer(varVerId);
DbProcess dbProcess = (DbProcess) hUtil.executeQueryReturnUniqueResult(session, sql, params);
if(dbProcess != null){
int val = dbProcess.getVal();
map.put(new Integer(varVerId),new Integer(val));
populatePreceedingVarVerHashMap(val,session,map);
}
}

private void clearExistingVarVerChgLog(int varVerId,Session session){
String sql = "delete from VarVerChgLog v where v.varVer.id=?";
Query q = session.createQuery(sql);
q.setInteger(0,varVerId);
q.executeUpdate();
}

While the query in the second method '
String sql = "delete from VarVerChgLog v where v.varVer.id=?";'
is recoginzed by IntelliJ as a hibernate query and i can see the mappings for the VarVerChgLog while typing in the query, the same is not true for the query
String sql = "from DbProcess d where d.varVer.id=? and d.schma='eV12'";

Can anybody give me an idea why this is. I can use the HQL console to execute the query and i have made sure the resource mapping exists in the hibernate.cfg.xml file.

Also Intellij does not like the '?' mark in the query
delete from VarVerChgLog v where v.varVer.id=?
It shows a red line underneath it and a red mark also shows up in the gutter giving a false impression that an error exists in code. Is there a way to fix this

Any help will be appreciate. The autocomplete on the queries will be a much appreciated feature when I have tons of them to write right now.
Reply With Quote
  #2  
Old 02-29-2008, 02:06 PM
Maxim Mossienko (JetBrains)
Guest
 
Default Re: Hibernate mappings - how do JAVA classes recognize it

This is known problem which should be solved in last IDEA 7 EAP build.

ranjana14 wrote:
> I have a java class that has two methods
>
> private void populatePreceedingVarVerHashMap(int varVerId, Session session,Map map) {
> String sql = "from DbProcess d where d.varVer.id=? and d.schma='eV12'";
> Object[] params = new Object[1];
> params[0] = new Integer(varVerId);
> DbProcess dbProcess = (DbProcess) hUtil.executeQueryReturnUniqueResult(session, sql, params);
> if(dbProcess != null){
> int val = dbProcess.getVal();
> map.put(new Integer(varVerId),new Integer(val));
> populatePreceedingVarVerHashMap(val,session,map);
> }
> }
>
> private void clearExistingVarVerChgLog(int varVerId,Session session){
> String sql = "delete from VarVerChgLog v where v.varVer.id=?";
> Query q = session.createQuery(sql);
> q.setInteger(0,varVerId);
> q.executeUpdate();
> }
>
> While the query in the second method '
> String sql = "delete from VarVerChgLog v where v.varVer.id=?";'
> is recoginzed by IntelliJ as a hibernate query and i can see the mappings for the VarVerChgLog while typing in the query, the same is not true for the query
> String sql = "from DbProcess d where d.varVer.id=? and d.schma='eV12'";
>
> Can anybody give me an idea why this is. I can use the HQL console to execute the query and i have made sure the resource mapping exists in the hibernate.cfg.xml file.
>
> Also Intellij does not like the '?' mark in the query
> delete from VarVerChgLog v where v.varVer.id=?
> It shows a red line underneath it and a red mark also shows up in the gutter giving a false impression that an error exists in code. Is there a way to fix this
>
> Any help will be appreciate. The autocomplete on the queries will be a much appreciated feature when I have tons of them to write right now.



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"
Reply With Quote
  #3  
Old 02-29-2008, 02:18 PM
ranjana14
Guest
 
Default Re: Hibernate mappings - how do JAVA classes recognize it

I have figured out the answer to my own question:

The method call hUtil.executeQueryReturnUniqueResult - is actually a wrapper for the session.createQuery(sql) with the some additonal checks

If I remove this method call and put session.createQuery(sql) in its place the sql statement
from DbProcess d where d.varVer.id=? and d.schma='eV12'
starts to act as if it is a recognizable hibernate query

Its a workaround but that should do for now
Reply With Quote
  #4  
Old 02-29-2008, 02:23 PM
ranjana14
Guest
 
Default Re: Hibernate mappings - how do JAVA classes recognize it

I am new to this forum - can you tell me how to get this build.
I just upgraded IntelliJ 5.0 with IntelliJ7.0.2 two days ago
Reply With Quote
  #5  
Old 03-02-2008, 09:33 PM
Gregory Shrago (JetBrains)
Guest
 
Default Re: Hibernate mappings - how do JAVA classes recognize it

Hello, ranjana14!

The second method has a direct "hibernate.session" method invocation
which is captured and thererfore the "String sql" is recognised as the
hql constant. Unfortunately the first method has not.

The '?' mark error should be fixed in 7.0.3.

Regards,
Gregory Shrago

ranjana14 wrote:
> I have a java class that has two methods
>
> private void populatePreceedingVarVerHashMap(int varVerId, Session session,Map map) {
> String sql = "from DbProcess d where d.varVer.id=? and d.schma='eV12'";
> Object[] params = new Object[1];
> params[0] = new Integer(varVerId);
> DbProcess dbProcess = (DbProcess) hUtil.executeQueryReturnUniqueResult(session, sql, params);
> if(dbProcess != null){
> int val = dbProcess.getVal();
> map.put(new Integer(varVerId),new Integer(val));
> populatePreceedingVarVerHashMap(val,session,map);
> }
> }
>
> private void clearExistingVarVerChgLog(int varVerId,Session session){
> String sql = "delete from VarVerChgLog v where v.varVer.id=?";
> Query q = session.createQuery(sql);
> q.setInteger(0,varVerId);
> q.executeUpdate();
> }
>
> While the query in the second method '
> String sql = "delete from VarVerChgLog v where v.varVer.id=?";'
> is recoginzed by IntelliJ as a hibernate query and i can see the mappings for the VarVerChgLog while typing in the query, the same is not true for the query
> String sql = "from DbProcess d where d.varVer.id=? and d.schma='eV12'";
>
> Can anybody give me an idea why this is. I can use the HQL console to execute the query and i have made sure the resource mapping exists in the hibernate.cfg.xml file.
>
> Also Intellij does not like the '?' mark in the query
> delete from VarVerChgLog v where v.varVer.id=?
> It shows a red line underneath it and a red mark also shows up in the gutter giving a false impression that an error exists in code. Is there a way to fix this
>
> Any help will be appreciate. The autocomplete on the queries will be a much appreciated feature when I have tons of them to write right now.

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:22 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.