-->
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.  [ 10 posts ] 
Author Message
 Post subject: Mapping problems with UserTypes
PostPosted: Tue Mar 28, 2006 4:36 am 
Newbie

Joined: Mon Mar 27, 2006 1:17 pm
Posts: 5
Hi,

I use Hibernate version 3.1 and MySQL 5.0.
I wanted to implement an enumeration type and did this by implementing two classes, a ParameterType and the ParameterTypeUserType.

In the mapping file of the class using the enum type, I inserted following lines:
<property
name="direction"
column="direction"
type="models.customtypes.ParameterTypeUserType"/>

Now I always get the following error message when running the ant-tasks:
build.xml:93: Schema text failed: Could not determine type for: models.customtypes.ParameterTypeUserType, for columns: [org.hibernate.mapping.Column(direction)]

and the following error message when running a java class:
10:33:36,546 INFO Environment:479 - Hibernate 3.1
10:33:36,546 INFO Environment:509 - hibernate.properties not found
10:33:36,562 INFO Environment:525 - using CGLIB reflection optimizer
10:33:36,562 INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling
10:33:36,687 INFO Configuration:1286 - configuring from resource: /hibernate.cfg.xml
10:33:36,687 INFO Configuration:1263 - Configuration resource: /hibernate.cfg.xml
10:33:37,171 INFO Configuration:468 - Reading mappings from resource: models/customtypes/ParameterTypeUserType.java
Exception in thread "main" org.hibernate.MappingException: Resource: models/customtypes/ParameterTypeUserType.java not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:478)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1443)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1411)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1392)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1368)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1288)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1274)


I'm totally confused. Thank you very much for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 12:42 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Looks like you tried putting a line like this in your configuration file and forgot to remove it when you found out it was wrong:
Code:
    <mapping resource="models/customtypes/ParameterTypeUserType.java"/>
Check through your .cfg.xml file(s) for something like that, and remove it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 3:00 am 
Newbie

Joined: Mon Mar 27, 2006 1:17 pm
Posts: 5
That was true. Now I deleted this row in my hibernate.cfg.xml file and I don't get any error message running a Java class but still running the ant tasks. Is that ok?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 5:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Oh yea, two seperate issues in one post, I missed that. The ant error is presumably beacuse your ParameterTypeUserType class either is not present in the location you specified, or else it doesn't implement the UserType interface. Whatever jar is providing the ParameterTypeUserType needs to be accessible to ant.. that is, it should be on your classpath.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 4:10 am 
Newbie

Joined: Mon Mar 27, 2006 1:17 pm
Posts: 5
tenwit wrote:
Oh yea, two seperate issues in one post, I missed that. The ant error is presumably beacuse your ParameterTypeUserType class either is not present in the location you specified, or else it doesn't implement the UserType interface. Whatever jar is providing the ParameterTypeUserType needs to be accessible to ant.. that is, it should be on your classpath.


The ParameterTypeUserType class implements UserType as follows:

package models.customtypes;

import org.hibernate.usertype.*;
import org.hibernate.*;
import java.sql.*;
import java.io.*;
import models.*;

public class ParameterTypeUserType implements UserType {

private static final int[] SQL_TYPES = {Types.VARCHAR};
public int[] sqlTypes() {return SQL_TYPES;}
public Class returnedClass() {return ParameterType.class;}
public boolean equals(Object x, Object y) {return x == y;}
public Object deepCopy(Object value) {return value;}
public boolean isMutable() {return false;}
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
throws HibernateException, SQLException{
String type = resultSet.getString(names[0]);
if (resultSet.wasNull()){
return null;
}
else{
return ParameterType.getInstance(type);
}
}

public void nullSafeSet(PreparedStatement statement, Object value, int index)
throws HibernateException, SQLException{
if(value==null){
statement.setNull(index, Types.VARCHAR);
}
else{
statement.setString(index, value.toString());
}
}

public int hashCode(Object o){
return o.hashCode();
}

public Serializable disassemble (Object value){
return (Serializable) deepCopy(value);
}

public Object assemble(Serializable cached, Object owner){
return deepCopy(cached);
}

public Object replace(Object original, Object target, Object owner)
throws HibernateException{
return original;
}
}

And it's located in the package models.customtypes. So I think the path in the mapping file should be ok, or isn't it?

What do you mean by 'need to be accesible to ant'? Which classpath I have to set in the build.xml file? (Sorry, I'm new to hibernate and this stuff)

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 5:14 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
If ant needs access to it, and it looks like it does from the error message, then you need to set it up before ant even starts running, so build.xml is too late. I could be wrong about that, my days of writing ant scripts are long past. However, if you put the appropriate directory or jar in your system classpath, it'll (almost) certainly work.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 11:37 am 
Newbie

Joined: Mon Mar 27, 2006 1:17 pm
Posts: 5
Thanks,

now my TestCase works, but ant still can't find the type.

Is it possible, that not every ant-version is compatible with customtypes?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 02, 2006 6:03 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It's not an ant issue. ant knows nothing about any of this. It might be an ant task issue, so you could check for a newer version of that. But most likely, it's just a classpath issue. You've told the ant task to load ParameterTypeUserType but you haven't put it on ant's classpath, so it can't find it. Once ant can find that class, the problem will go away.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 4:33 am 
Newbie

Joined: Mon Mar 27, 2006 1:17 pm
Posts: 5
Sorry, but it still doesn't work.
I inclued the classpath, I need, via Eclipse and it doesn't work. Then I tried it once again via the build.xml file and included the classpath in the schemaexport task. But still this confusing message:
build.xml:94: Schema text failed: Could not determine type for: models.customtypes.ParameterTypeUserType, for columns: [org.hibernate.mapping.Column(direction)]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 5:35 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Try manually doing whatever ant is doing. schemaexport sounds like it has something to do with hbm2dll (java -jar hibernate3.jar org.hibernate.tool.hbm2dll.SchemaExport, I think). If you can get it to run, then the problem is almost certainly with the classpath that ant is seeing. If you get it to produce the same error message as ant produces, then the error is probably a syntax error in the hbm.xml file that defines the Column class.


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