-->
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.  [ 4 posts ] 
Author Message
 Post subject: FIXED: Usertype not properly generated in Pojo
PostPosted: Thu Sep 16, 2010 12:32 pm 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
The database has a VARCHAR(1) field that may be Y or N, and I want to have it mapped as a Boolean in the entity class.

hibernate.reveng.xml has this:
Code:
  <table name="MY_TABLE">
    <column name="FLAG"
       type="com.company.lib.hibernate.usertypes.YNBooleanType"/>


YNBooleanType inherits from org.hibernate.type.BooleanType, so its getReturnedClass() function already does the right thing and returns Boolean.class.

However, the generated Pojo has
Code:
  @Column (name = "FLAG", nullable = false, length = 1)
  public YNBooleanType getFlag () {
    return this.flag;
  }


Now I knew that the standard reason for this is that the user type isn't on the classpath.
So I placed YNBooleanType in a jar file that I specifically added to the classpath. This didn't change anything.
In fact I think the class isn't loaded, I had added
Code:
  static {
    System.err.println ("YNBooleanType was loaded");
  }

to the class body, but the message never turned up (I do get "didn't report any primary key columns" message, so I'm pretty sure I'm looking at the right console).
Somehow it's ignoring the specified classpath.

I'm using the Classpath tab on the Hibernate Configuration from the Hibernate view.
Maybe that's the wrong classpath setting?

I'd like to make it log the classpath it's using to resolve user types - is there a way to raise the logging level when it's running inside Eclipse?


Top
 Profile  
 
 Post subject: Re: FIXED: Usertype not properly generated in Pojo
PostPosted: Tue Sep 21, 2010 2:22 pm 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
Turned out that subclassing a standard type like BooleanType is not the way to go, you need to write a subclass of UserType.
Hibernate's standard types are handled very differently from user types; for example, no user type can specify a type shorthand (which, incidentally, means you have to specify the full darn.long.user.type.fully.qualified.TypeName in hibernate.reveng.xml).

Oh. And the difference between a UserType and standard types can be as minor as having the standard types using getReturnedClasss() and UserType using returnedClass().
The kind of detail you tend to miss :-(


Top
 Profile  
 
 Post subject: Re: FIXED: Usertype not properly generated in Pojo
PostPosted: Fri Nov 30, 2012 1:34 pm 
Newbie

Joined: Fri May 18, 2012 5:04 pm
Posts: 4
Joachim Durchholz wrote:
no user type can specify a type shorthand (which, incidentally, means you have to specify the full darn.long.user.type.fully.qualified.TypeName in hibernate.reveng.xml).

I have a patch for that!. do you know if there is a ticket for it?


Top
 Profile  
 
 Post subject: Re: FIXED: Usertype not properly generated in Pojo
PostPosted: Tue Dec 25, 2012 9:19 pm 
Newbie

Joined: Thu Dec 20, 2012 11:11 pm
Posts: 6
Is there a way to ignore the foreign keys of all tables from my database ?


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