-->
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.  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Select new myBean(col1,col2,col_datetime)...
PostPosted: Thu Nov 18, 2004 12:44 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Hibernate version:
2.1.6

Full stack trace of any exception that occurs:
net.sf.hibernate.PropertyNotFoundException: no appropriate constructor in class: myPackage.myBean

at net.sf.hibernate.util.ReflectHelper.getConstructor(ReflectHelper.java:214)

at net.sf.hibernate.hql.QueryTranslator.renderSQL(QueryTranslator.java:560)

at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:155)

at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)

at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:294)

at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1562)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)

at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)

at system.TestDBAHibernate.<init>(TestDBAHibernate.java:15)

at system.CacheInit.<init>(CacheInit.java:14)

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 java.lang.Class.newInstance0(Class.java:308)

at java.lang.Class.newInstance(Class.java:261)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:987)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)

at org.apache.catalina.core.StandardService.start(StandardService.java:480)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)

at org.apache.catalina.startup.Catalina.start(Catalina.java:556)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:284)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:422)


Name and version of the database you are using:
Sybase ASE 12.5

Hi,

Hibernate seams to have a problem calling my bean's constructor. I'm doing a query and asking Hibernate to load the resultset into my class "myBean". The problem reside in the fact thet one of the retrieved column is of type (datetime - Sybase ASE type). When I remove that column from my query and from myBean, everything gets loaded fine.

I investigated the problem and found that the column datatype I get from the JDBC driver for the datetime column is of com.sybase.jdbc2.tds.SybTimestamp type. I tried changing the datatype of myBean's constructor to com.sybase.jdbc2.tds.SybTimestamp but I still get the same error.

So, to resume, when Hibernate calls myBean's constructor (with the timestamp argument type), I get the error listed above. I also get the error if I change the argument type to com.sybase.jdbc2.tds.SybTimestamp. I do not get the error if I remove the datetime column from the query and from myBean's constructor.

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 12:51 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Try to use the same type of date in your constructor (for example: java.util.Date/java.util.Calendar), that you specified in the mapping file.
Could you also post the errornous code and your mapping files?

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 1:51 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Thanks for your reply Dencel,

I didn't post the mapping file because I thought the "select new" wasn't using it. You see, myBean doesn't have a mapping file, I believe that Hibernate (net.sf.hibernate.util.ReflectHelper.getConstructor) finds the right constructor by looking at the number of parameters (compare with the number of columns retrieved in the SQL statement). Then it tries to see if it can map the column datatype received in the resultset with one of it's primitive datatype. Since the column datatype received in the resultset is "com.sybase.jdbc2.tds.SybTimestamp", Hibernate comes to the conclusion that the constructor is invalid.


Here the column mapping of the table I try to retrieve the column from:
<property
name="changeDate"
type="java.sql.Timestamp"
column="Change_Date"
not-null="true"
length="23"
/>


Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 4:07 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Me again,

Could it be that the "net.sf.hibernate.dialect.SybaseDialect" need to be modified to enable it to map "com.sybase.jdbc2.tds.SybTimestamp" to Timestamp type ?

Just a thought.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 4:47 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Sybase Timestamp is an ugly case
  1. from JDBC point of view its binary data.
  2. you must not write to this column, it's updated by sybase up on every write access to the column


If you have chance, get rid of the Timestamp, if not maybe a UserType helps (I've this on my todo list as well ;-) ).

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 4:56 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Thanks for your post ernst_pluess but, I'm not writing to that column nor do I plan to do so either. I'm just trying to retrieve it using the "select new myBean(col, col, coldatetime)...".

I've been looking around in the Hibernate code and it starting to look like a bug. Unless it's the Sybase JDBC implementation that's buggy.

Anyhow, I'm kind of stuck on this issue. If at least I had a full understanding of how (and where) Hibernate maps a column datatype to it's own, I could try to implement the SybTimestamp somehow.

Well, I hope one of the Hibernate developer reads this post (sooner the better).

Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 3:01 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Quote:
Anyhow, I'm kind of stuck on this issue. If at least I had a full understanding of how (and where) Hibernate maps a column datatype to it's own, I could try to implement the SybTimestamp somehow.


You can overwrite that in a UserType.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 3:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you haven't posted much about the query, the mapping etc. so not much i can help with :)

...but i can say that select new ofcourse uses the mapping files as the HQK query still needs to be translated into the proper sql.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 11:32 am 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
max wrote:
you haven't posted much about the query, the mapping etc. so not much i can help with :)

...but i can say that select new ofcourse uses the mapping files as the HQK query still needs to be translated into the proper sql.



You're right Max, I didn't give you much to work with. It's just that the Query is joining 6 tables and returning columns from each of them and I didn't want to sent more then necessary.

Here's the mapping file from which the SybTimestamp's coming from (look for name="changeDate"):

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

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="hibernate.Form"
table="FORMS"
>

<id
name="formId"
type="java.lang.Long"
column="Form_ID"
>
<generator class="assigned" />
</id>

<property
name="cid"
type="java.lang.Integer"
column="CID"
not-null="true"
length="6"
/>
<property
name="formLanguage"
type="java.lang.String"
column="Form_Language"
not-null="true"
length="1"
/>
<property
name="formStatus"
type="java.lang.String"
column="Form_Status"
not-null="true"
length="1"
/>
<property
name="transferredToAmisDate"
type="java.sql.Timestamp"
column="Transferred_To_AMIS_Date"
length="23"
/>
<property
name="transferredToAmisIndicator"
type="java.lang.String"
column="Transferred_To_AMIS_Indicator"
length="1"
/>
<property
name="createUserId"
type="java.lang.String"
column="Create_User_ID"
not-null="true"
length="3"
/>
<property
name="createDate"
type="java.sql.Timestamp"
column="Create_Date"
not-null="true"
length="23"
/>
<property
name="changeUserId"
type="java.lang.String"
column="Change_User_ID"
not-null="true"
length="3"
/>
<property
name="changeDate"
type="java.sql.Timestamp"
column="Change_Date"
not-null="true"
length="23"
/>

<!-- associations -->
<!-- bi-directional many-to-one association to Application -->
<many-to-one
name="application"
class="hibernate.Application"
not-null="true"
>
<column name="Appl_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to WebSubsystem -->
<many-to-one
name="webSubsystem"
class="hibernate.WebSubsystem"
not-null="true"
>
<column name="Subsystem_ID" />
</many-to-one>

</class>
</hibernate-mapping>


I checked the datatype of that column in the resultset (I called the same HQL without the SELECT NEW). I did a getClass().getName() on the column and it returned "com.sybase.jdbc2.tds.SybTimestamp".

Here's the HQL:

Iterator it = session.createQuery(
"select new portFolio.PortFolioBean2( Form.application.applId, " +
"Application.programId, " +
"Application.applTitle, " +
"Form.cid, " +
"Form.webSubsystem.subsystemId, " +
"Application.letterOfIntentInd, " +
"Cod.shortNameFrench, " +
"Cod.shortNameEnglish, " +
"WebSubsystem.displayNameFrench, " +
"WebSubsystem.displayNameEnglish, " +
"Form.formStatus, " +
"Form.formLanguage, " +
"Form.changeDate, " +
"Form.formId) " +
"from Application Application, " +
"WebSubsystem WebSubsystem, " +
"WebSubsystemCrossref WebSubsystemCrossref, " +
"Cod Cod, " +
"Person Person, " +
"Form Form " +
"WHERE ( Application.grantType *= Cod.code) and " +
"( Application.programId = WebSubsystem.program.programId ) and " +
"(WebSubsystem.subsystemId = WebSubsystemCrossref.comp_id.bySubsystemId) AND " +
"( Application.webId = Person.cid ) and " +
"( Form.webSubsystem.subsystemId = WebSubsystem.subsystemId ) and " +
"( Form.application.applId = Application.applId ) and " +
"( Application.webId = Form.cid ) and " +
"( ( Application.webId = 12345 ) AND " +
"( (WebSubsystem.grantType = Application.grantType OR " +
"Application.grantType is null) AND " +
"(Application.letterOfIntentInd is null OR " +
"Application.letterOfIntentInd = WebSubsystem.letterOfIntentInd)) AND " +
"WebSubsystemCrossref.comp_id.byPortfolioSubsystemId = 56 AND " +
"Application.finalReportInd = 'N' ) AND " +
"DATEDIFF(day,Form.changeDate, getdate()) < 120 " +
"order by 2 ASC, 3 ASC, 1 ASC ").list().iterator();


Here the portFolio.PortFolioBean2 class:


public class PortFolioBean2 {
private Integer web_id;
private Long appl_id;
private Integer program_id;
private Integer subSystem_id;
private Long form_id;

private String appl_title;
private String letter_Of_Intent_Ind;
private String grantType_f;
private String grantType_e;

private String formName_f;
private String formName_e;
private String formLanguage;
private String form_Status;
private Timestamp change_Date;

/* Default constructor*/
public PortFolioBean2() {
}

/* constructor for loading all fields*/
public PortFolioBean2(Long appl_id, Integer program_id, String appl_title,
Integer web_id, Integer subSystem_id,
String letter_Of_Intent_Ind, String grantType_f,
String grantType_e, String applTitle_f,
String applTitle_e, String form_Status,
String formLanguage, Timestamp change_Date,
Long form_ID) {
this.appl_id = appl_id;
this.program_id = program_id;
this.appl_title = appl_title;
this.web_id = web_id;
this.subSystem_id = subSystem_id;
this.letter_Of_Intent_Ind = letter_Of_Intent_Ind;

this.formName_f = grantType_f + applTitle_f;
this.formName_e = grantType_e + applTitle_e;

this.formLanguage = formLanguage;
this.form_Status = form_Status;
this.change_Date = change_Date;
this.form_id = form_ID;

}

I tried changing the column's datatype in the mapping and the PortFolioBean2 constructor to "com.sybase.jdbc2.tds.SybTimestamp" and that didn't solved the problem.

Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I would suggest you start by trimming down your example to just include the "bad" column/field and we can start from there ....also try to do a select without the new X() construct and tell us what instance the returned objects in the Object[] are.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 12:50 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
max wrote:
I would suggest you start by trimming down your example to just include the "bad" column/field and we can start from there ....also try to do a select without the new X() construct and tell us what instance the returned objects in the Object[] are.


Here it is Max.

I didn't change the FORM mapping file but I changed the HQL and did a .getClass() on each column of the resulSet.

HQL:
Iterator it = session.createQuery(
"select Form.application.applId, " +
"Form.cid, " +
"Form.changeDate, " +
"Form.formId " +
"from Form Form " +
"WHERE Form.cid = 21282").list().iterator();


LOG:
INFO [main] (TestDBAHibernate.java:24) - TestDBAHibernate applId : class java.lang.Long

INFO [main] (TestDBAHibernate.java:25) - TestDBAHibernate cid : class java.lang.Integer

INFO [main] (TestDBAHibernate.java:26) - TestDBAHibernate changeDate : class com.sybase.jdbc2.tds.SybTimestamp

INFO [main] (TestDBAHibernate.java:27) - TestDBAHibernate formId : class java.lang.Long


Let me know if you need more. For this test, I didn't think I needed to trim down the Form.hbm.xml file.


Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 1:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm...I guess a problem could be that the SybTimestamp is created with another classloader than the one your code is actully running in/under.

Then the classes have the same name, but is actually not equal!

Does this shed a light for you ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 1:27 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Hmmm... Not really ;).

The "com.sybase.jdbc2.tds.SybTimestamp" is a class in the Jconn2.jar. Which is the latest Sybase JDBC implementation. There's a new JConn3 that just came out but I wasn't able to put my hand on it until now.

I've been trying to understand the last method call in the stacktrace (net.sf.hibernate.util.ReflectHelper.getConstructor). In that method, it looks to me that Hibernate tries to map the ResulSet column datatype to an Hibernate type. Is that right?

If so, how can I tell Hibernate to map "com.sybase.jdbc2.tds.SybTimestamp" to it's timestamp datatype? If you know how, could you please give me an example on how to do this.

Thx


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 2:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
It's the following code I think that fails:

Code:
final boolean ok = params[j].isAssignableFrom( types[j].getReturnedClass() ) || (params[j] == ( (PrimitiveType) types[j] ).getPrimitiveClass());


The isAssignableFrom method is dependent on the two classes to be in the same classloader hiearchy - and in this situation I guess they are not.

So, the getReturnedClass().getName() and params[j].getName() probably can return the same classname, but are actually two different classes because they do not have the same classloader.

And there is not much Hibernate can do about that - even if it ignored the classloader, the JVM would complain when we called the constructor because the types would not be compatible!

I will suggest that you place the jdbc driver in the global classpath of your appserver to just verify that it is this classloader issue you are seeing.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 2:57 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Ok Max. I did what you asked me to do. I've put my JDBC driver (JConn2.jar) in D:\Borland\JBuilder2005\thirdparty\jakarta-tomcat-5.0.27\common\lib.

I still get the same datatype "com.sybase.jdbc2.tds.SybTimestamp".

Did I put it in the right folder? I searched my drives to make sure I didn't have any other copy of JConn2.jar and the only copy I found was that one.

So, is there any work around you can think of?

Thx


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 23 posts ]  Go to page 1, 2  Next

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.