-->
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: JavaFX BooleanProperty cant not be mapped in Hibernate
PostPosted: Mon Mar 06, 2017 9:25 am 
Newbie

Joined: Mon Mar 06, 2017 9:15 am
Posts: 18
Hi everyone, its my first time here and i have a problem while learning Hibernate:

My Class Article (not the full class though):

Code:
public Article() {
    private BooleanProperty en = new SimpleBooleanProperty(false);

    //getter Methode:
    public boolean isEn(){
         return en.get();
    }
    public BooleanProperty enProperty(){
         return en;
    }
    public void setEn(boolean en){
         this.en.set(en);
    }
}


my mapping XML :
Quote:
<property column="b_english_version" name="en" type="javafx.beans.property.BooleanProperty"/>



And i get this problem :

Quote:
MappingException : Could not determine type for: javafx.beans.property.BooleanProperty, at table t_fit_article, for columns: ... b_english_version]


but when i Change the type to boolean then its no longer wrong.

Can someone explain why ? Thanks in advance !


Top
 Profile  
 
 Post subject: Re: JavaFX BooleanProperty cant not be mapped in Hibernate
PostPosted: Mon Mar 06, 2017 10:37 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You get that exception because Hibernate does not know how to handle BooleanProperty.

If you really want to store your entity like that, then you need to create a custom Type to handle the BooleanProperty. So, you have two options:

1. You can implement the UserType interface as explained in this article
2. You can use the AbstractSingleColumnStandardBasicType and provide a Java and a SQL descriptor as described in this article

Then, you will also have to annotate the type with the @Type annotation and provide the custom type class at the mapping level.


Top
 Profile  
 
 Post subject: Re: JavaFX BooleanProperty cant not be mapped in Hibernate
PostPosted: Tue Mar 07, 2017 8:02 am 
Newbie

Joined: Mon Mar 06, 2017 9:15 am
Posts: 18
Hi vlad,

at first thanks for your answer. The reason i use xml mapping because in some tutorial its still used and am still learning :)

Is there any way to work around in this situation? i mean i still read the boolean value but from database in the moment the object is created it will run a function that convert this boolean into BooleanProperty ?

Is there anyway to do that with Hibernate ? I still have many value in database which needs to convert into my class-based-value, an easy example is like this :

A B

True True


But in my class you need to pass those boolean values to a function which returns a string ( this string is what i really need). Is there anyway to tell Hibernate to do that when it creates instances of my class ?

Thanks!


Top
 Profile  
 
 Post subject: Re: JavaFX BooleanProperty cant not be mapped in Hibernate
PostPosted: Tue Mar 07, 2017 8:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can also use an AttributeConvertor. I guess it will address your use case.


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.