-->
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.  [ 2 posts ] 
Author Message
 Post subject: exception getting property value with CGLIB, PLEASE HELP!
PostPosted: Mon Mar 27, 2006 7:34 pm 
Newbie

Joined: Mon Mar 27, 2006 5:48 pm
Posts: 3
Hibernate version: 3.1

CONTENT:
1. THE FILENAMES THAT ARE USED IN THIS QUESTION
2. THE SOURCE CODE FOR THE .java FILES
2.1 ProjectManager.java
2.2 MainReportManager.java
2.3 Driver.java

3. THE SOURCE CODE FOR THE .hbm.xml FILES
3.1 project.hbm.xml
3.2 mainreport.hbm.xml

4. THE ERROR MESSAGE WHEN I RUN THIS ALL
5. RELATIONS BETWEEN MAINREPORT AND PROJECT
6. THE QUESTIONS



note:
The package reportsystem is where i have all my persistent classes, the DAO files, and the .hbm.xml mapping files.



1. THE FILENAMES THAT ARE USED IN THIS QUESTION:

The DAO files (I call mine DAO files for Manager files) are:
- ProjectManager.java
- MainReportManager.java
- Driver.java (just a simple class with main() method, not a DAO file)

The Mapping files (filename.hbm.xml) are:
- project.hbm.xml
- mainreport.hbm.xml



2. THE SOURCE CODE FOR THE .java FILES:

2.1 ProjectManager.java:
// import ...
public class ProjectManager {

public ProjectManager() {
HibernateUtil.beginTransaction();
}

public void storeInformation(String projectid, String custinfo) {
try {
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();

Project project = new Project();

project.setProject_id(projectid);
project.setCust_info(custinfo);

session.save(project);
tx.commit();
session.close();
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
}// end storeInformation()
}// end class ProjectManager


2.2 MainReportManager.java
//import ...
public class MainReportManager {

public MainReportManager() {
HibernateUtil.beginTransaction();
}

public void storeInformation(String projectid,
Date d, String clientid, String dept,
String type_of_report,
String summary, String groupe,
String title_of_report,
String index_term1, String index_term2,
String index_term3,
String index_term4, String report_type,
int idreport,
int distribution_statement, int rev_nr) {
try {

Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();

MainReport mainRep = new MainReport();
long reportid = theLargestRepId(); //look below this method
Long reportnr = new Long(reportid);

mainRep.setReportnr(reportnr);
mainRep.setProjectid(projectid);
mainRep.setLast_date(d);
mainRep.setClientid(clientid);
mainRep.setDept(dept);
mainRep.setType_of_report(type_of_report);
mainRep.setSummary(summary);
mainRep.setGroupe(groupe);
mainRep.setTitle_of_report(title_of_report);
mainRep.setIndex_term_1(index_term1);
mainRep.setIndex_term_2(index_term2);
mainRep.setIndex_term_3(index_term3);
mainRep.setIndex_term_4(index_term4);
mainRep.setReport_type(report_type);
mainRep.setIdreport(idreport);
mainRep.setDistribution_statement(distribution_statement);
mainRep.setRev_nr(rev_nr);

session.save(mainRep);
tx.commit();
session.close();

} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
}// end storeInformation()

public long theLargestRepId(){

Long largestId = null;
long value;

try {
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();

String sqlQuery = "from reportsystem.MainReport";
largestId = (Long) session.createQuery(sqlQuery).uniqueResult();

if(largestId == null) {
value = -1;
} else {
value = largestId.longValue();
}

tx.commit();
//session.flush();

} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
if(value == -1){
return 1;
}
else return value;
}
} //end class MainReportManager


2.3 Driver.java
//import ...
public class Driver {

static MainReportManager repMan = new MainReportManager();

public Driver() {}

public static void main(String args[]) {
Date date = new Date();

//long verdi = rm.theLargestRepId(); // this works
//System.out.println(verdi); // without any problem

/* Trying to store information on the database.
This is where the program "crashes" and gives the error message
i've written below in section 4 */
repMan.storeInformation("NO-DEF", date, "clientid", "dept", "type of r",
"This is the summary", "the groupe", "title of rep",
"term1", "term2", "term3", "term4", "The type",
2, 3, 7);
} //end main
}// end class Driver



3. THE SOURCE CODE FOR THE .hbm.xml FILES

3.1 project.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="reportsystem.Project" table="project">
<id name="project_id" column="project_id">
</id>

<property name="cust_info" type="text">
<column name="cust_info" />
</property>

</class>
</hibernate-mapping>

3.2 mainreport.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="reportsystem.MainReport" table="report">

<composite-id name="reportnr" class="reportsystem.MainReport">
<key-property name="reportnr" column="reportnr" type="long"/>
<key-property name="projectid" column="projectid" />
</composite-id>

<many-to-one name="projectid" class="reportsystem.Project"
insert="false" update="false">
<column name="projectid" />
</many-to-one>

<property name="last_date" type="date" >
<column name="last_date" />
</property>

<property name="clientid" >
<column name="clientid" />
</property>

<property name="dept" >
<column name="dept" />
</property>

<property name="type_of_report" >
<column name="type_of_report" />
</property>

<property name="summary" type="text" >
<column name="summary" />
</property>

<property name="groupe" >
<column name="groupe" />
</property>

<property name="title_of_report" type="text" >
<column name="title_of_report" />
</property>

<property name="index_term_1" >
<column name="index_term_1" />
</property>

<property name="index_term_2" >
<column name="index_term_2" />
</property>

<property name="index_term_3" >
<column name="index_term_3" />
</property>

<property name="index_term_4" >
<column name="index_term_4" />
</property>

<property name="report_type" >
<column name="report_type" />
</property>

<property name="idreport" type="integer" >
<column name="idreport" />
</property>

<property name="distribution_statement" type="integer" >
<column name="distribution_statement" />
</property>

<property name="rev_nr" type="integer" >
<column name="rev_nr" />
</property>

</class>
</hibernate-mapping>



4. THE ERROR MESSAGE WHEN I RUN THIS ALLexeptions.InfrastructureException: org.hibernate.PropertyAccessException: exception getting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of reportsystem.MainReport.?

at reportsystem.MainReportManager.storeInformation(MainReportManager.java:71)

at util.Driver.main(Driver.java:40)

Caused by: org.hibernate.PropertyAccessException: exception getting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of reportsystem.MainReport.?

at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:79)

at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:307)

at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:158)

at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:69)

at org.hibernate.engine.EntityKey.<init>(EntityKey.java:42)

at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:147)

at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)

at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)

at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)

at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:559)

at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)

at org.hibernate.impl.SessionImpl.save(SessionImpl.java:543)

at reportsystem.MainReportManager.storeInformation(MainReportManager.java:66)

... 1 more

Caused by: java.lang.ClassCastException

at reportsystem.MainReport$$BulkBeanByCGLIB$$87f025c8.getPropertyValues(<generated>)

at net.sf.cglib.beans.BulkBean.getPropertyValues(BulkBean.java:48)

at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:76)

... 16 more

Exception in thread "main"



5. RELATIONS BETWEEN MAINREPORT AND PROJECT


What i'm trying to do is to make two primary keys in my MAINREPORT
table which consists of one foriegn key.
This foriegn key is the primary key in PROJECT table.
The relation between MAINREPORT and PROJECT is many-to-one.



6. THE QUESTIONS

6.1 (The most important question) What can i do to make this work and store information on my database without any problem.
What am i doing wrong?
Please help me, i'm REALLY stuck here.


6.2 I don't know what the exeptions.InfrastructureException (The error message in section 4) is telling me. What does it mean?

6.3 I have another situation in another mapping file that looks like this:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="reportsystem.LiquidReport" table="liquid_r">

<composite-id name="report_reportnr"
class="reportsystem.LiquidReport">

<key-property name="report_reportnr"
column="report_reportnr" type="long"/>

<key-property name="report_projectid"
column="report_projectid" type="string"/>
</composite-id>

<many-to-one name="report_reportnr"
class="reportsystem.MainReport"
insert="false" update="false">
<column name="report_reportnr" />
<column name="report_projectid" />
</many-to-one>


<property name="report_date" type="date">
<column name="report_date" />
</property>

<property name="user_username">
<column name="user_username" not-null="true" />
</property>

<property name="nameOfProperty"/>
...
...
...
</class>
</hibernate-mapping>

The "builder/compiler" doesn't complain about this, but what I'm trying to obtain here is to make primary keys from TWO foreign keys. Is this possible in Hibernate, and does the mapping file above do this correctly?
If not, how shall I do it?




I appreciate ANY help I can get, one little hint or trick may help me solve this. I'm working on my main project hand-in, and I'm under alot of stress because I can't make this work, so please help ! :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 8:32 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
First, do exactly what the exception tells you to:
Exception output wrote:
org.hibernate.PropertyAccessException: exception getting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of reportsystem.MainReport.?

There isn't enough info in the exception generated by the optimized code to tell you exactly what property you are misusing. And it is a simple fix, you're just putting a value of the wrong type into some property somewhere.

Second, check your mapping. You have told hibernate that the class of the id is the same as the class of the entity:
Code:
<class name="reportsystem.MainReport" table="report">
  <composite-id name="reportnr" class="reportsystem.MainReport">
  ...
You haven't included the java code for MainReport, but it's almost certainly not its own id.

Third, reconsider your mapping. If you want the primary key to be two foreign keys, why are they defined as key-property? You probably want key-many-to-one.

Fourth, please use code tags when posting code. You've gone to a lot of trouble to post neatly, then phpBB ruins it by left-aligning and using a proportional typeface. Ick.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.