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.  [ 6 posts ] 
Author Message
 Post subject: Problem persisting classes with protected accessor methods
PostPosted: Wed Dec 22, 2004 11:43 pm 
Newbie

Joined: Mon Dec 20, 2004 9:08 pm
Posts: 9
Hibernate version:
2.1.7c

Mapping documents:

<component name="dateOfBirth" class="com.orchestral.common.date.PartialDate">
<property name="timestamp" column="dateOfBirth" type="timestamp"/>
<property name="precisionChar" column="dateOfBirthPrec" type="character"/>
<property name="nanoseconds" column="dateOfBirthNano" type="int"/>
</component>


Full stack trace of any exception that occurs:
[ERROR] (hibernate.cfg.Configuration ) - Could not compile the mapping document
net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property timestamp in class com.orchestral.common.date.PartialDate
at net.sf.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:131)
at net.sf.hibernate.mapping.Property.getSetter(Property.java:178)
at net.sf.hibernate.cfg.Binder.bindComponent(Binder.java:906)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1053)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:363)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1018)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:974)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:902)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:888)
at com.orchestral.cdr.CDRDBBaseImpl.<init>(CDRDBBaseImpl.java:93)
at com.orchestral.cdr.CDRLoaderTest.<init>(CDRLoaderTest.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:102)
at junit.framework.TestSuite.<init>(TestSuite.java:66)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.getTest(RemoteTestRunner.java:360)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:398)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

Name and version of the database you are using:
SQL server 2000

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

[DEBUG] (hibernate.cfg.Binder ) - Mapped property: timestamp -> dateOfBirth, type: timestamp
[DEBUG] (hibernate.cfg.Binder ) - Mapped property: precisionChar -> dateOfBirthPrec, type: character
[DEBUG] (hibernate.cfg.Binder ) - Mapped property: nanoseconds -> dateOfBirthNano, type: integer
[ERROR] (hibernate.cfg.Configuration ) - Could not compile the mapping document
net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property timestamp in class com.orchestral.common.date.PartialDate
at net.sf.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:131)
at net.sf.hibernate.mapping.Property.getSetter(Property.java:178)
at net.sf.hibernate.cfg.Binder.bindComponent(Binder.java:906)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1053)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:363)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1018)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:974)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:902)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:888)
at com.orchestral.cdr.CDRDBBaseImpl.<init>(CDRDBBaseImpl.java:93)
at com.orchestral.cdr.CDRLoaderTest.<init>(CDRLoaderTest.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:102)
at junit.framework.TestSuite.<init>(TestSuite.java:66)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.getTest(RemoteTestRunner.java:360)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:398)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 9:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Impossible to tell without you showing your class. Protected methods are no problem for hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 4:14 pm 
Newbie

Joined: Mon Dec 20, 2004 9:08 pm
Posts: 9
basically I have parent clas called AccurateDate:

public class AccurateDate implements Serializable, Cloneable {

private Timestamp timestamp;

private int nanoseconds = -1;

{some more code here...}

protected void setTimestamp(Timestamp timestamp) {
if (timestamp != null) {
this.timestamp = (Timestamp) timestamp.clone();
updateTimestampNanos();
}
else
{
this.timestamp = null;
}
}

protected Timestamp getTimestamp() {
Timestamp returnedTimestamp = this.getDate();
if (!DBMS_SUPPORTS_MILLISECONDS) {
returnedTimestamp.setNanos(0);
}
return returnedTimestamp;
}

{similar accessor for the nanosec which is proetcted}


Then I have another class which is a subclass of this and this is what I'm trying to persist, here is the code:


public class PartialDate extends AccurateDate implements Serializable, Cloneable {
private PrecisionCode precision;

protected char getPrecisionChar() {
return precision.getPrecision();
}


protected void setPrecisionChar(char precision) {
this.precision = PrecisionCode.valueOf(precision);
}
}


here is my mapping for this: -- the partial date will be a component for a persistable class

<component name="dateOfBirth" class="com.orchestral.index.common.data.date.PartialDate">

<property name="timestamp" column="dateOfBirth" />
<property name="precisionChar" column="dateOfBirthPrecision" />
<property name="nanoseconds" column="dateOfBirthNanoseconds" />

</component>


The problem that I'm having is everytime I try to persist this class, Hibernate throws an exception that says it couldn't find the property called timestamp.

If I try to change the accessor methods to public, then it works without any problems -- so i guess my question is I thought hibernate supports public, protected or even private accessor methods?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 6:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hm, I wonder why this should not work ... are you running under some kind of SecurityManager restrictions? Sure you made no typos?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 6:59 pm 
Newbie

Joined: Mon Dec 20, 2004 9:08 pm
Posts: 9
Yep, I'm sure I haven't made any typo errors as I've checked it many times just to be sure it's not something silly like that. I am not aware of any securityManager that will cause this problem. Also, the things is if I cahnge the accessor methods into public then I don't get any errors. Some other team in our company has been using the PartialDate class in their project and the weired thing is they can get it to persist using the same mapping files as the one I'm using.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 6:04 pm 
Newbie

Joined: Mon Dec 20, 2004 9:08 pm
Posts: 9
I've finally found out what's causing the problem. It just so happens that we are using an obfuscator for the java classes and the protected methods are being changed into some arbitrary method name, in which case this is the reason that hibernate cannot find the propected methods.


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