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.

4 comments
Comment actions Permalink

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!"

0
Comment actions Permalink

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

0
Comment actions Permalink

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

0
Comment actions Permalink

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.

0

Please sign in to leave a comment.