-->
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: Hibernate safes URL as binary - can it be as String?
PostPosted: Sat Sep 04, 2010 3:51 am 
Newbie

Joined: Sat Jan 07, 2006 10:04 pm
Posts: 5
Hi,
I have some URL in my persistence Objects, like:

Code:
@Entity
public class Image
{
  (...)
  private URL imageURL;
  (...)
}


Hibernate stores them as "VARBINARY", so when I browse the database with an SQL-Client I cannot see (nor debug) what data really is stored.

Can I somehow configure that URLs are stored (and loaded) as String-Objects? Is there any annotation to change the column-type?

Thanks and Best Regards,
Tobias


Top
 Profile  
 
 Post subject: Re: Hibernate safes URL as binary - can it be as String?
PostPosted: Sat Sep 04, 2010 5:33 am 
Newbie

Joined: Tue Aug 24, 2010 7:04 am
Posts: 14
There are a list of options:
  • Define the property imageURL as a field of type String with String getter and setter and do the mapping outside of the bean
  • Define the property imageURL as a field of type String and do the mapping within the getter and setter operations
  • Use as custom type mapper as described in Hibernate documentation and in the following blog. This way binds you to the custom type mapping support of the JPA implementation.

I think I would prefer option 2!

Kind regards,
Michael


Top
 Profile  
 
 Post subject: Re: Hibernate safes URL as binary - can it be as String?
PostPosted: Sat Sep 04, 2010 7:55 am 
Newbie

Joined: Sat Jan 07, 2006 10:04 pm
Posts: 5
Hey thanks!

Sometimes its that simple... I did not know, that I am allowed to have getters and setters with different type than the field itself!

Thanks for the hint,
Tobias


Top
 Profile  
 
 Post subject: Re: Hibernate safes URL as binary - can it be as String?
PostPosted: Sat Sep 04, 2010 11:12 am 
Newbie

Joined: Tue Aug 24, 2010 7:04 am
Posts: 14
You must only annotate your fields and not the getter methods. I do the same in my beans and do the mapping in my getter and setter method, so I can provide types in my API without binding me to Hibernate.

Kind regards,
Michael


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.