[hibernate-dev] Naming strategies and join tables
Steve Ebersole
steve at hibernate.org
Tue Feb 23 13:09:57 EST 2016
Well first I'd probably ask on user communication channels, not the
developer mailing list. That said, have you read the User Guide,
especially the revamped User Guide in 5.1?
On Tue, Feb 23, 2016 at 7:13 AM Adriano Santos <adriano.nego at gmail.com>
wrote:
> First all, where (exactly) can I get the correct way to mapping all the
> relations? We are always finding many differents mapping forms and this can
> be terrible to beginners. I still dont know if we have some tutorial or
> book like that, but I'd like... Anybody here knows?
>
> Este e-mail foi enviado por um computador sem vírus e protegido pelo
> Avast.
> www.avast.com <https://www.avast.com/sig-email>
> <#msg-f:1526971223964960053_DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> On Tue, Feb 23, 2016 at 9:36 AM, Steve Ebersole <steve at hibernate.org>
> wrote:
>
>> Well first, technically isn't that mapping incorrect? That should use
>> @CollectionTable rather than @JoinTable. I am not sure that makes a
>> difference, but in the interest of mapping things properly...
>>
>> That being said... the whole premise of the legacy EJB3NamingStrategy was
>> to prefer the use of table names over the use of entity names. The table
>> name here is `abstractprojet`; there is no table named
>> `projetdiffusion`. So
>> personally I believe the new behavior is correct, whereas the old behavior
>> was incorrect if it really produced `projetdiffusion_technologies` here.
>>
>> My $.02
>>
>>
>>
>>
>> On Tue, Feb 23, 2016 at 3:31 AM Emmanuel Bernard <emmanuel at hibernate.org>
>> wrote:
>>
>> > To be honest I cannot make up my mind to decide which behavior is more
>> > correct. I can see both as valid.
>> >
>> > > On 22 Feb 2016, at 18:07, Steve Ebersole <steve at hibernate.org> wrote:
>> > >
>> > > It is also important to understand that lots of Hibernate code calling
>> > into
>> > > NamingStrategy did so in quite inconsistent ways. We decided that
>> > > consistency of the calling was more important moving forward. So
>> while
>> > > ImplicitNamingStrategyLegacyJpaImpl strives to be compatible with the
>> > > older EJB3NamingStrategy,
>> > > we won't do that at the compromise of consistency in the calls.
>> > >
>> > > Step into ImplicitNamingStrategyLegacyJpaImpl#determineJoinTableName
>> and
>> > > find out:
>> > > 1) where this particular call is coming from
>> > > 2) what information is passed in
>> > >
>> > >
>> > >
>> > >
>> > > On Mon, Feb 22, 2016 at 6:34 AM Guillaume Smet <
>> guillaume.smet at gmail.com
>> > >
>> > > wrote:
>> > >
>> > >> Important point: AbstractProjet uses SINGLE_TABLE inheritance.
>> > >>
>> > >> On Mon, Feb 22, 2016 at 12:10 PM, Guillaume Smet <
>> > guillaume.smet at gmail.com
>> > >>>
>> > >> wrote:
>> > >>
>> > >>> Hi,
>> > >>>
>> > >>> I'm migrating another application to 5.x and have the following
>> issue
>> > >> with
>> > >>> the new naming strategies.
>> > >>>
>> > >>> We used EJB3NamingStrategy and are now using
>> > >>> ImplicitNamingStrategy*Legacy*JpaImpl which is advertised as being
>> its
>> > >>> replacement.
>> > >>>
>> > >>> The model is the following:
>> > >>> @Entity
>> > >>> AbstractProjet
>> > >>>> @Entity
>> > >>> @DiscriminatorValue(value = "ProjetDiffusion")
>> > >>> public class ProjetDiffusion extends AbstractProjet {
>> > >>> @ElementCollection
>> > >>> @Enumerated(EnumType.STRING)
>> > >>> @JoinTable(uniqueConstraints = {
>> > >>> @UniqueConstraint(columnNames = { "projetdiffusion_id",
>> "technologies"
>> > >> }) })
>> > >>> private List<ProjetTechnologie> technologies =
>> > >>> Lists.newArrayList();
>> > >>>
>> > >>> Before the upgrade to 5, the join table was called
>> > >>> projetdiffusion_technologies and the column was projetdiffusion_id.
>> > >>>
>> > >>> After the upgrade to 5, the join table is called
>> > >>> abstractprojet_technologies and the column abstractprojet_id. Thus,
>> we
>> > >> have
>> > >>> an error on the creation of the unique constraint.
>> > >>>
>> > >>> Is this change expected?
>> > >>>
>> > >>> --
>> > >>> Guillaume
>> > >>>
>> > >> _______________________________________________
>> > >> hibernate-dev mailing list
>> > >> hibernate-dev at lists.jboss.org
>> > >> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>> > >>
>> > > _______________________________________________
>> > > hibernate-dev mailing list
>> > > hibernate-dev at lists.jboss.org
>> > > https://lists.jboss.org/mailman/listinfo/hibernate-dev
>> >
>> >
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>
>
>
>
> --
>
> Adriano Araújo Santos
>
>
> *"A mente que se abre a uma nova ideia jamais voltará ao seu tamanho
> original."*
>
>
>
More information about the hibernate-dev
mailing list