These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: a joined-subclass problem,help plz.
PostPosted: Wed Mar 26, 2008 6:10 am 
Newbie

Joined: Thu Oct 14, 2004 10:36 pm
Posts: 5
Hello all.
I am using hibernate 3.2.4 sp1,mysql5.0,jdk1.6,and mysql-connector-java-5.0.7.
When has not increased the joined-subclass fragment, this method can worked fine,after adding joined-subclass, presents the

following mistake(Below is the tomcat console output message).

Hibernate: select * from metadata as m where m.sort_id=? and m.city_id IN (select m2.city_id from metadata m2 where

m2.meta_id in (select t1.meta_id from tag t1 where t1.name in (?))) group by m.meta_id limit
03-26 17:37:44 INFO [http-80-1] (NullableType.java:182) - could not read column value from result set: clazz_; Column 'clazz_' not found.
03-26 17:37:44 WARN [http-80-1] (JDBCExceptionReporter.java:77) - SQL Error: 0, SQLState: S0022
03-26 17:37:44 ERROR [http-80-1] (JDBCExceptionReporter.java:78) - Column 'clazz_' not found.
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
.........


Caused by: java.sql.SQLException: Column 'clazz_' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:987)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2749)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:237)
at org.hibernate.type.IntegerType.get(IntegerType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:1442)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1284)
at org.hibernate.loader.Loader.getRow(Loader.java:1206)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 42 more



Hibernate version: 3.2.4.sp1

Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="net.yumt.model.Metadata" table="metadata">
<id name="metaId" type="java.lang.String">
<column name="meta_id" length="48" />
<generator class="uuid" />
</id>
<many-to-one name="sort" class="net.yumt.model.Sort" fetch="select" lazy="false">
<column name="sort_id" length="48" not-null="true" />
</many-to-one>
<many-to-one name="city" class="net.yumt.model.City" fetch="select" lazy="false">
<column name="city_id" length="48" />
</many-to-one>
<property name="title" type="java.lang.String">
<column name="title" />
</property>
<set name="tags" inverse="true">
<key>
<column name="meta_id" length="48" />
</key>
<one-to-many class="net.yumt.model.Tag" />
</set>


<joined-subclass name="net.yumt.model.Hotel" table="hotel">
<key column="meta_id"/>
<property name="ranking" type="java.lang.Integer">
<column name="ranking" />
</property>
<property name="address" type="java.lang.String">
<column name="address" />
</property>
<set name="rooms" inverse="true" cascade="all">
<key>
<column name="hotel_id" length="48"/>
</key>
<one-to-many class="net.yumt.model.Room" />
</set>
</joined-subclass>

<joined-subclass name="net.yumt.model.Room" table="room">
<key column="meta_id"/>
<property name="bed" type="java.lang.Integer">
<column name="bed" />
</property>
<many-to-one name="hotel" class="net.yumt.model.Hotel">
<column name="hotel_id" length="48" />
</many-to-one>
</joined-subclass>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
StringBuffer sb = new StringBuffer();
sb.append("select * from metadata as m where");
if (!StringUtil.isNull(sortId)) {
sb.append(" m.sort_id=? and");
}
sb
.append(" m.city_id IN (select m2.city_id from metadata m2 where m2.meta_id in (select t1.meta_id from tag t1 where t1.name in (?))) group by m.meta_id");
SQLQuery sql = getSession().createSQLQuery(sb.toString()).addEntity(Metadata.class);

sb.delete(0, sb.length());
System.out.println(sb);
for (String t : tags) {
sb.append(t);
sb.append(",");
}
if (!StringUtil.isNull(sortId)) {
sql.setString(0, sortId);
sql.setString(1, sb.deleteCharAt(sb.length() - 1).toString());
} else {
sql.setString(0, sb.deleteCharAt(sb.length() - 1).toString());
}
if (perPage > 0) {
sql.setFirstResult((page - 1) * perPage);
sql.setMaxResults(perPage);
}


return sql.list();


Debug level Hibernate log excerpt:
03-26 17:57:46 DEBUG [http-80-1] (AbstractBatcher.java:366) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
03-26 17:57:46 DEBUG [http-80-1] (AbstractBatcher.java:401) - select * from metadata as m where m.sort_id=? and m.city_id IN (select m2.city_id from metadata m2 where m2.meta_id in (select t1.meta_id from tag t1 where t1.name in (?))) group by m.meta_id limit ?
Hibernate: select * from metadata as m where m.sort_id=? and m.city_id IN (select m2.city_id from metadata m2 where m2.meta_id in (select t1.meta_id from tag t1 where t1.name in (?))) group by m.meta_id limit ?
03-26 17:57:46 DEBUG [http-80-1] (AbstractBatcher.java:484) - preparing statement
03-26 17:57:46 DEBUG [http-80-1] (NullableType.java:133) - binding '4' to parameter: 1
03-26 17:57:46 DEBUG [http-80-1] (NullableType.java:133) - binding 'Architecture' to parameter: 2
03-26 17:57:46 DEBUG [http-80-1] (AbstractBatcher.java:382) - about to open ResultSet (open ResultSets: 0, globally: 0)
03-26 17:57:46 DEBUG [http-80-1] (Loader.java:694) - processing result set
03-26 17:57:46 DEBUG [http-80-1] (Loader.java:699) - result set row: 0
03-26 17:57:46 DEBUG [http-80-1] (NullableType.java:172) - returning 'ff8080811762fafb01176cc63c750906' as column: meta_id
03-26 17:57:46 DEBUG [http-80-1] (Loader.java:1173) - result row: EntityKey[net.yumt.model.Metadata#ff8080811762fafb01176cc63c750906]
03-26 17:57:46 INFO [http-80-1] (NullableType.java:182) - could not read column value from result set: clazz_; Column 'clazz_' not found.
03-26 17:57:46 DEBUG [http-80-1] (AbstractBatcher.java:389) - about to close ResultSet (open ResultSets: 1, globally: 1)
03-26 17:57:46 DEBUG [http-80-1] (AbstractBatcher.java:374) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
03-26 17:57:47 DEBUG [http-80-1] (AbstractBatcher.java:533) - closing statement
03-26 17:57:47 DEBUG [http-80-1] (JDBCExceptionReporter.java:69) - could not execute query [select * from metadata as m where m.sort_id=? and m.city_id IN (select m2.city_id from metadata m2 where m2.meta_id in (select t1.meta_id from tag t1 where t1.name in (?))) group by m.meta_id]
java.sql.SQLException: Column 'clazz_' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:987)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2749)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:237)




I has never add clazz_ to my object.It's grotesque.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 6:18 am 
Newbie

Joined: Thu Oct 14, 2004 10:36 pm
Posts: 5
btw:The generated SQL has been executed on mysql shell console.

I'm confused.has any inadequate configuration?

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 10:09 pm 
Newbie

Joined: Thu Oct 14, 2004 10:36 pm
Posts: 5
I'm sorry to my english.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 10:24 pm 
Beginner
Beginner

Joined: Tue Dec 27, 2005 1:13 pm
Posts: 25
Location: Kingston, ON, Canada
Can you check if you have a property mapped to field 'clazz_' ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 10:27 pm 
Newbie

Joined: Thu Oct 14, 2004 10:36 pm
Posts: 5
lcbdl wrote:
Can you check if you have a property mapped to field 'clazz_' ?


the "clazz_" has not been used never.the field "clazz_" generated by hibernate.so I'm confused.


Last edited by aeonsun on Wed Mar 26, 2008 10:30 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 10:29 pm 
Beginner
Beginner

Joined: Tue Dec 27, 2005 1:13 pm
Posts: 25
Location: Kingston, ON, Canada
If you have property='adsfa' column='clazz_', and there isn't a column named 'clazz_' in the database. That will cause this problem, I think.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 10:35 pm 
Newbie

Joined: Thu Oct 14, 2004 10:36 pm
Posts: 5
lcbdl wrote:
If you have property='adsfa' column='clazz_', and there isn't a column named 'clazz_' in the database. That will cause this problem, I think.


to:lcbdl.thank you.
maybe you are not earnest to read my post message.my mapping file is posted above.
thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 6:55 pm 
Newbie

Joined: Thu May 08, 2008 6:23 pm
Posts: 1
Similar problem here... Difference I use annotations and postgres 8.3. I'm trying to execute this SQL Query:
Code:
Session session = HibernateUtil.getSessionFactory().openSession();
String sql = "SELECT * FROM " +
                "(planoprocedimento AS PP INNER JOIN plano AS PL ON PL.plan_id = PP.plan_id) " +
                   "INNER JOIN procedimento AS P ON P.proc_id = PP.proc_id " +
                "WHERE PP.plan_id = :id AND P.proc_descricao SIMILAR TO :name " +
                "ORDER BY P.proc_descricao";

List<PlanoProcedimento> list = (ArrayList<PlanoProcedimento>) session.createSQLQuery(sql)
                                         .addEntity("planoProc", PlanoProcedimento.class)
                                         .addJoin("plano", "planoProc.plano")
                                         .addJoin("procedimento", "planoProc.procedimento")
                                         .setLong("id", id)
                                         .setString("name", name + '%')
                                         .list();


The thing is, I tested this SQL and it worked pretty well, but when trying to execute it with hibernate (code above), I got this exception:
Code:
18:34:47,687 ERROR JDBCExceptionReporter:72 - The column name clazz_ wasn't found in this ResultSet.
08/05/2008 18:34:47 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
org.postgresql.util.PSQLException: The column name clazz_ wasn't found in this ResultSet.
   at org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2450)
   at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2312)
   at org.hibernate.type.IntegerType.get(IntegerType.java:28)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:139)
   at org.hibernate.loader.Loader.getInstanceClass(Loader.java:1433)
   at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1275)
   at org.hibernate.loader.Loader.getRow(Loader.java:1197)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
   at org.hibernate.loader.Loader.doQuery(Loader.java:689)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2157)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2041)
   at org.hibernate.loader.Loader.list(Loader.java:2036)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
   at br.ufms.sipas.dao.impl.PlanoDAOImpl.findProcsByName(PlanoDAOImpl.java:83)
   at br.ufms.sipas.action.PlanoAction.selectProcsByLetter(PlanoAction.java:97)


I don't have any column called "clazz_", for sure. It seems that Hibernate is assuming that this column exists because I use a Joined Inheritance class. Here some code of the classes involved:

Class Procedimento:
Code:
package br.ufms.sipas.bo;

import javax.persistence.*;

@Entity
@Table(name="procedimento")
@Inheritance(strategy=InheritanceType.JOINED)
public class Procedimento implements java.io.Serializable, Comparable<Procedimento>{
   private static final long serialVersionUID = 1L;

   // Several attributes, all correctly mapped
   ...
}


Class PlanoProcedimento:
Code:
package br.ufms.sipas.bo;

import javax.persistence.*;

@Entity
@Table(name="planoprocedimento", uniqueConstraints=@UniqueConstraint(columnNames={"plan_id", "proc_id"}))
public class PlanoProcedimento implements java.io.Serializable, Comparable<PlanoProcedimento>{
   private static final long serialVersionUID = 1L;

   // Several attributes
   ...

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name="plan_id", nullable=false)
   private Plano plano;

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name="proc_id", nullable=false)
   private Procedimento procedimento;

   // Rest of the class
   ...
}


Class Plano:
Code:
package br.ufms.sipas.bo;

import javax.persistence.*;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
import java.util.Date;
import java.util.SortedSet;
import java.util.TreeSet;

@Entity
@Table(name="plano")
public class Plano implements java.io.Serializable, Comparable<Plano>{
   private static final long serialVersionUID = 1L;

   
   // Several attributes
   ...

   @OneToMany(mappedBy="plano", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
   @Sort(type=SortType.NATURAL)
   private SortedSet<PlanoProcedimento> procedimentos = new TreeSet<PlanoProcedimento>();

   // Rest of the class
   ...
}


Basically, Plano and Procedimento have a n-to-n relationship with extra attributes, and that's why I use the PlanoProcedimento class. Procedimento can be extended, and as I already sayed, this is done using Joined Inheritance. My mapping works well and that's the only problem I had till the moment.

Any ideas? Is this a bug? I'm doing something wrong? Any help will be appreciated! If any futher information is need, please let me know. And sorry for the bad english.

Thanks in advance,
Marcelo.

-------------------------
Brazil


Top
 Profile  
 
 Post subject: suggestion
PostPosted: Sun May 11, 2008 8:49 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Hi,
I'm referring to the original query at the beginning of this post. My question is: what exactly should return from the query? metadata entities? If so, change the query from:
select * from metadata m...
to
select m from metadata m...

let me know if it helped.


Top
 Profile  
 
 Post subject: Re: a joined-subclass problem,help plz.
PostPosted: Thu Jan 06, 2011 11:20 am 
Newbie

Joined: Thu Jan 06, 2011 11:15 am
Posts: 1
I'm having the same problem and hoping you found a solution to your problem after all this time. If so can you share with us what was done?

I'm also wondering what was done to get the debug output shown in the original post. I have log4j.logger.org.hibernate=DEBUG set in my log4.properties file, but I'm not seeing the same amount of information as you are and I'm having a hard time tracking down which column the error is against.

Thanks for any information you can provide.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.