Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How to utilize the metadata model in mappedBy attribute?
PostPosted: Wed Apr 05, 2017 8:59 am 
Newbie

Joined: Wed Jul 13, 2016 10:40 pm
Posts: 19
JPA Metadata Model may generate the atrribute information of the entity class(Topic)
so that I can get the information by the field of metadata model(Topic_) but not String constant
, which really set free for us to modify the attribute name of entity class.

And I found that the mappedBy attribute in @OneToMany.. can not utilize the metadata model.

I have tried this way that

Code:
@OneToMany(mappedBy="${Topic_.person.getName()}")


, but failed.


Top
 Profile  
 
 Post subject: Re: How to utilize the metadata model in mappedBy attribute?
PostPosted: Wed Apr 05, 2017 9:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1275
Of course, it failed! That's the expected behavior.

The mappedBy attribute takes the name of the property. You cannot use Metamodel for that. Metamodel is used to construct type-safe entity queries.

So, the JPA annotations have no notation of a dynamic Expression Language (e.g. ${Topic_.person.getName()}). You have to provide the name of the property.

So, what happens you modify a property without renaming the mappedBy attribute? Well, Hibernate will not even bootstrap.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: How to utilize the metadata model in mappedBy attribute?
PostPosted: Wed Apr 05, 2017 10:19 am 
Newbie

Joined: Wed Jul 13, 2016 10:40 pm
Posts: 19
vlad wrote:
Of course, it failed! That's the expected behavior.

The mappedBy attribute takes the name of the property. You cannot use Metamodel for that. Metamodel is used to construct type-safe entity queries.

So, the JPA annotations have no notation of a dynamic Expression Language (e.g. ${Topic_.person.getName()}). You have to provide the name of the property.

So, what happens you modify a property without renaming the mappedBy attribute? Well, Hibernate will not even bootstrap.


Thanks, I am clear what metadata model use for.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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.