Joined: Thu Nov 02, 2006 7:35 pm Posts: 4
|
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.1
Mapping documents:
<class name="app.bo.CompanyLight" table="company">
<!-- Primary Key --> <id name="company_id" column="company_id"> <generator class="increment"/> </id> <!-- Direct Data Properties --> <property name="name" column="name"/> <property name="description" column="description"/> </class>
<class name="app.bo.Company" table="company"> <!-- Primary Key --> <id name="company_id" column="company_id"> <generator class="increment"/> </id> <!-- Direct Data Properties --> <property name="name" column="name"/> <property name="description" column="description"/> <!-- Relationship References --> <component name="latest_numbers" class="app.set.LatestDataSet"> <set name="psetVal" lazy="false" cascade="save-update"> <key column="company_id"/> <one-to-many class="app.bo.LatestData"/> </set> </component>
Code between sessionFactory.openSession() and session.close(): Session session = HibernateUtil.getSessionFactory().openSession(); // if(!session.isOpen()) // session = HibernateUtil.getSessionFactory().openSession(); //session.setCacheMode(CacheMode.REFRESH); Transaction tx = session.beginTransaction(); Query q = session.createQuery("from CompanyLight"); personList = (List) q.list(); for(int i=0;i<personList.size();i++) { CompanyLight p = (CompanyLight)personList.get(i); System.out.println(p.getCompany_id() + p.getDescription()); }
Full stack trace of any exception that occurs:
Name and version of the database you are using:MySQL
The generated SQL (show_sql=true): Hibernate: select company0_.company_id as company1_0_, company0_.name as name0_, company0_.description as descript3_0_ from company company0_ Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select psetval0_.company_id as company5_1_, psetval0_.latest_number_id as latest1_1_, psetval0_.latest_number_id as latest1_1_0_, psetval0_.number_value as number2_1_0_, psetval0_.text_value as text3_1_0_, psetval0_.datatype_id as datatype4_1_0_, psetval0_.company_id as company5_1_0_ from latest_data psetval0_ where psetval0_.company_id=? Hibernate: select companylig0_.company_id as company1_0_, companylig0_.name as name0_, companylig0_.description as descript3_0_ from company companylig0_
1great company 2superb place 3All Inovation 5divine 6divine 7dfghdfgh 8haroon 9Dello 10google 11harommmbkkk ioio 12good energy nnn mm kkoopp 1great company 2superb place 3All Inovation 5divine 6divine 7dfghdfgh 8haroon 9Dello 10google 11harommmbkkk ioio 12good energy nnn mm kkoopp
Records are appearing twice!
I have classes in the following structure:
class a {
int x;
int y;
}
class b extends class a{
Set z;
}
I want to populate a list with class a only first, and then based on my need populate class b. This is similar to lazy loading, but I want to deliberately split it out between two classes, to satisfy the framework i'm using.
For this reason i've to specify 2 mapping files, both referring to the same table, since class b also needs the table used by class a.
The problem I'm runing into is that if I populate just class a, the result set I'm getting is doubled (duplicate records for each row). If I populate Class b, then everything is fine, but I want the collection of class a, not class b.
I'm sure Hibernate has the technology to solve this problem, but I'm struggling to find a solution.
Thanks!
Haroon
|
|