-->
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.  [ 3 posts ] 
Author Message
 Post subject: Embeddables and common classe or interface
PostPosted: Tue Nov 24, 2015 4:33 pm 
Newbie

Joined: Tue Nov 24, 2015 3:52 pm
Posts: 12
Hi,

In an Entity classe I have a collection :
Code:
   @ElementCollection
   List<Marker> markers;


Marker is an interface:
Code:
public interface Marker {

}


The Marker interface is implemented by 2 classes:

Code:
@Embeddable
public class TextMarker implements Marker {
...
}

@Embeddable
public class MediaMarker implements Marker {
...}


When I deploy my war I get the following Hibernate error :
Code:
org.hibernate.MappingException: Could not determine type for: com.visiativ.my3dplayer.persistence.Marker, at table: Player_markers, for columns: [org.hibernate.mapping.Column(markers)]


And If I change the Marker interface to a class:

Code:
@Embeddable
public class Marker {

}
@Embeddable
public class TextMarker extends Marker {
...
}

@Embeddable
public class MediaMarker extends Marker {
...}


I get this error :

Code:
Caused by: org.hibernate.MappingException: Could not instantiate collection persister org.hibernate.persister.collection.BasicCollectionPersister
   at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:242) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
   at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:201) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
   at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:430) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
   ... 13 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
   at org.hibernate.persister.collection.AbstractCollectionPersister.generateSelectSizeString(AbstractCollectionPersister.java:1020) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
   at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:528) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
   at org.hibernate.persister.collection.BasicCollectionPersister.<init>(BasicCollectionPersister.java:77) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.8.0_20]
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [rt.jar:1.8.0_20]
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_20]
   at java.lang.reflect.Constructor.newInstance(Constructor.java:408) [rt.jar:1.8.0_20]
   at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:231) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
   ... 17 more



So what's the correct way to model my use case in JPA ?
Thanks


Top
 Profile  
 
 Post subject: Re: Embeddables and common classe or interface
PostPosted: Wed Nov 25, 2015 10:16 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
(1) Please use class, not interface
(2) Hibernate does not support the OOP inheritence for @Embeddable type util now(I also think it's unnecessary to support it), If you want to use inheritence, please use @Entity


Top
 Profile  
 
 Post subject: Re: Embeddables and common classe or interface
PostPosted: Mon Nov 30, 2015 4:49 am 
Newbie

Joined: Tue Nov 24, 2015 3:52 pm
Posts: 12
Thanks !


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