-->
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.  [ 9 posts ] 
Author Message
 Post subject: Hibernate logging without an Application Server
PostPosted: Wed Mar 03, 2004 10:36 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 5:48 am
Posts: 20
I have the following error:
net.sf.hibernate.QueryException: unresolved property: createdate [null]
at net.sf.hibernate.persister.EntityPersister.toColumns(EntityPersister.java:965)
at net.sf.hibernate.expression.Expression.getColumns(Expression.java:282)
at net.sf.hibernate.expression.Order.toSqlString(Order.java:34)
at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:51)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3149)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:65)
...

Since this is the most info I can get from the stack trace, is there a way to get additional Hibernate output without using an Application Server?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 10:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Of course, just put a log4j.properties in your classpath root and set log levels as you like. A sample one is in the hibernate distribution.


Top
 Profile  
 
 Post subject: Stuck
PostPosted: Wed Mar 03, 2004 11:02 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 5:48 am
Posts: 20
Thanks for your response.
Which classpath root? For hibernate? I have put it in my project's classpath root. The contents of the file are like Greek to me. The example log4j is just as bad. I did however change the line:
log4j.logger.net.sf.hibernate=info
to
log4j.logger.net.sf.hibernate=debug

Still nothing is being printed out. Where do I find the output? The full file is below:


### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ##

log4j.rootLogger=warn, stdout

log4j.logger.net.sf.hibernate=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace

### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=info

### log prepared statement cache activity ###
log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=info


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 11:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Your projects classpath root should be okay. All logging info is printed to the console in the configuration you posted. Take a look at the log4j homepage for more documentation.


Top
 Profile  
 
 Post subject: Ok
PostPosted: Wed Mar 03, 2004 11:13 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 5:48 am
Posts: 20
Ok cool. Am I correct in assuming that hibernate would log some stuff if it generated the error that I showed in my first posting? If not, then perhaps you have an idea what is causing the error. Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 11:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I suspect you are trying to add an Order to a criteria for a property which does not exist. hard to tell without your code and mappings.


Top
 Profile  
 
 Post subject: Code and mapping
PostPosted: Thu Mar 04, 2004 3:05 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 5:48 am
Posts: 20
Below are the main parts of the custom type DateTimeType and the mapping file for the table (the table has 2 columns, CREATEDATE and CREATETIME, both of type DATE). You will notice that DateTimeTYpe converts data for the DateTime class. Perhaps you can see something wrong?

Extract from table mapping file
============================================================
<property
name="dateTime"
type="com.lbss.framework.persistence.DateTimeType">
<column name="CREATEDATE"/>
<column name="CREATETIME"/>
</property>


DateTimeType.java (custom type)
============================================================
public class DateTimeType implements UserType {
public DateTimeType() {
if (log.isDebugEnabled()) {
log.debug("DateTimeType constructor called");
}
}

public int[] sqlTypes ()
{
return types;
}

public Class returnedClass ()
{
return com.lbss.framework.DateTime.class;
}

public boolean equals (Object x, Object y) throws HibernateException
{
if (x==y) return true;
if (x==null || y==null) return false;
return ((com.lbss.framework.DateTime)x).equals( (com.lbss.framework.DateTime) y);
}

public Object nullSafeGet (ResultSet rs,
String[] names,
Object owner)
throws HibernateException,
SQLException
{
java.util.Date theDate = (java.sql.Date)Hibernate.DATE.nullSafeGet(rs, names[0]);
java.util.Date theTime = (java.sql.Date)Hibernate.DATE.nullSafeGet(rs, names[1]);

// TODO: Verify this
if ((theDate == null) && (theTime == null))
return null;

System.out.println("DATETIMETYPE: java.util.Date DATE: " + theDate.toString());
System.out.println("DATETIMETYPE: java.util.Date TIME: " + theTime.toString());

// Convert the sql date and time to Vectus Date and Time, and make into a Vectus DateTime object

com.lbss.framework.Date returnDate = new com.lbss.framework.Date(theDate.getTime());
com.lbss.framework.Time returnTime = new com.lbss.framework.Time(theTime.getTime());

System.out.println("DATETIMETYPE: java.util.Date DATE: " + theDate.toString());
System.out.println("DATETIMETYPE: java.util.Date TIME: " + theTime.toString());

com.lbss.framework.DateTime returnDateTime = new com.lbss.framework.DateTime(returnDate, returnTime);
return returnDateTime;
}

public void nullSafeSet(PreparedStatement st,
Object value,
int index)
throws HibernateException,
SQLException {

java.sql.Date setDate = null;
java.sql.Date setTime = null;

if (value != null) {
// Convert the given object into a SQL Date, so that Hibernate can
// handle the statement preparation
com.lbss.framework.DateTime dateTime = (com.lbss.framework.DateTime) value;

com.lbss.framework.Date theDate = dateTime.getDate();
com.lbss.framework.Time theTime = dateTime.getTime();

GregorianCalendar cvtDate = new GregorianCalendar(theDate.year(),
theDate.month(),
theDate.day());
GregorianCalendar cvtTime = (GregorianCalendar)theTime.getCalendar();

setDate = new java.sql.Date(cvtDate.getTimeInMillis());
setTime = new java.sql.Date(cvtTime.getTimeInMillis());
}

// Actually prepare the statement
Hibernate.DATE.nullSafeSet(st, setDate, index);
Hibernate.DATE.nullSafeSet(st, setTime, index + 1);
}

public Object deepCopy (Object value) throws HibernateException
{
if (value == null)
return null;

//com.lbss.framework.Date copy = new com.lbss.framework.Date((com.lbss.framework.Date)value);
com.lbss.framework.DateTime copy = new com.lbss.framework.DateTime(((com.lbss.framework.DateTime)value).getDate(), ((com.lbss.framework.DateTime)value).getTime());
return copy;
}

public boolean isMutable () {
return true;
}

private static final Log log = LogFactory.getLog(DateTimeType.class);
private static final int[] types = {Types.DATE, Types.DATE};
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 4:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I suspect you use createdate in your criteria building somewhere where you should use dateTime - really hard to tell without your code.


Top
 Profile  
 
 Post subject: Great stuff!
PostPosted: Thu Mar 04, 2004 5:51 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 5:48 am
Posts: 20
Thanks, you were right, I had forgotten to remove criteria ordering based on createdate and createtime. A final question, as you can see, DateTimeType implements UserType. In order to query on DateTime objects, do I need to implement CompositeUserType? I have read that implementing CompositeUserType allows one to dereference queries. What does this mean? Thanks!


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