ElementCollection « Map « JPA Q&A

1. JPA: @ElementCollection and InheritanceType.TABLE_PER_CLASS -> Duplicate column name    stackoverflow.com

I've created the following scenario:

@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class MyEntity implements Serializable{
    protected Long id;

2. JPA 2 -- Using @ElementCollection in CriteriaQuery    stackoverflow.com

    public class Person {

        private List<Location> locations;


3. Hibernate - @ElementCollection - Strange delete/insert behavior    stackoverflow.com

public class Person {

    @CollectionTable(name = "PERSON_LOCATIONS", joinColumns = @JoinColumn(name = "PERSON_ID"))
    private List<Location> locations;



public class Location ...

4. Using @ElementCollection in CriteriaQuery    stackoverflow.com

public enum ReportStatus { 

public class Work {
    List<ReportStatus> reportStatuses;
Given the following structure, I'd like ...

5. Specify foreign key constraint name when using Map and @ElementCollection with Hibernate    stackoverflow.com

I have a sort of exotic mapping for a field:

@CollectionTable(name = "studentGradeLevel", joinColumns = @JoinColumn(name = "studentId"))
@MapKeyJoinColumn(name = "schoolYearId")
@Column(name = "gradeLevel", nullable = false)
@ForeignKey(name = "fkStudentGrade2Student")
private Map<SchoolYear, GradeLevel> gradeLevels;
SchoolYear is an ...

6. jpa Hibernate @ElementCollection    stackoverflow.com

I have a question which bothers me a bit. When i use @ElementCollection in my entity hibernate (3.5) generates me a table without any constraints. Important Edit My Entity is a subclass ...

7. Hibernate @ElementCollection - Better solution needed    stackoverflow.com

I'm using Hibernate 3.5.a-Final as ORM-Layer in a web application. I've got several Beans with the same code-sniplet wich makes me think that this design isn't the best one around. But ...

8. JPA: @ElementCollection with SortedMap    stackoverflow.com

I have a problem when trying to map a SortedMap with Byte-Arrays as values via JPA. My mapping looks as follows:

    @ElementCollection(fetch = FetchType.LAZY)
    @Lob ...

9. Hibernate ClassCastException when performing merge/ update of class that uses @ElementCollection with Enums    stackoverflow.com

I have a class that gives the exception below when saving. This is puzzling because I can retrieve the data fine. The error still occurs even if I perform a merge ...

10. Hibernate unsaved instance exception using @ElementCollection    stackoverflow.com

I am getting an exception

object references an unsaved transient instance - save the transient instance before flushing
thrown in the following code:
public void addThing(String key, String someData) {

11. jpa criteriabuilder for @ElementCollection    stackoverflow.com

What's the equivalent CriteriaBuilder for this simple jpl?

TypedQuery<Sample> query = em.createQuery("from Sample s, In(s.friends) f where f = :friend", Sample.class).setParameter("friend", friend);
// query yields: select sample0_.id as id39_ from Sample sample0_ inner ...

12. How to make a like query to @ElementCollection of type map?    stackoverflow.com

I have a class like this:

class MyEntity {
    Map<String, String> properties;
I'd like to find out which MyEntity entities have a property value that matches ...

13. How to perform subquery on an @ElementCollection within the same entity?    stackoverflow.com

Consider the following entity.

public class Member {
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String memberName;


14. Does JPA @ElementCollection annotation always produce an one-to-many relationship?    stackoverflow.com

For this question, consider the following sample:

public class File {
    public static enum Permission { READABLE, WRITEABLE, EXECUTABLE }


15. Hql "in" statement doesn't work with an @ElementCollection    stackoverflow.com

I have a class collection property with @ElementCollection and @Enumerated(EnumType.ORDINAL)
I am trying to perform an in statement on that collection however in the generated sql i get this -> {non-qualified-property-ref} in ...

16. @ElementCollection: bad column names    forum.hibernate.org

Alas no. In order to move on, I simply used @AttributeOverrides to explicit define the name and design of each column. If you build your own database schema, you only have to define the name of the columns. Obvious, this isn't ideal, nor reusable. But, for my immediate needs it suffices. Best of Luck.

17. Hibernate issue with @ElementCollection and @MapKeyColumn    forum.hibernate.org

Hi, all. I'm getting 4 items in result of Code: criteria.list() instead of expected one. Has anyone faced the same issue? Looks like Hibernate issue. If FetchType is set to LAZY of @ElementCollection fetch strategy it works as expected. I'm getting as many items as items in extraProperties. Sample code is provided. Code: @Entity @Table(name = "source") public class Source implements ...

18. @ElementCollection has to use JOIN in Hbernate    forum.hibernate.org

agoncal Post subject: Re: @ElementCollection has to use JOIN in Hbernate Posted: Tue Nov 02, 2010 5:55 am Newbie Joined: Sun Aug 06, 2006 8:54 am Posts: 15 Here is what I get (with log level at debug) : Code: 10:53:14,512 DEBUG QueryTranslatorImpl:272 - parse() - HQL: SELECT b FROM org.beginningee6.tutorial.Book b WHERE 'scifi' member of b.tags 10:53:14,527 DEBUG ...

19. Maintain LinkedHashMap insertion order on @ElementCollection    forum.hibernate.org

Users u = new Users(); u.setUsername("foo"); Map m = new LinkedHashMap(); Addresses addr = new Addresses(); addr.setCity("Jersey City"); ...

20. @ElementCollection @MapKeyColumn: can't update 'null' value    forum.hibernate.org

//no hibernate specific annotations used import javax.persistence.* @Entity(name = "MYENTITY") @SecondaryTables(value = @SecondaryTable(name = "MYENTITY_L10N", pkJoinColumns = @PrimaryKeyJoinColumn(name = "PK_MYENTITY"))) public class MyEntity { @Id @Column(name = "PK") private int pk; @ElementCollection(fetch = FetchType.EAGER) @MapKeyColumn(name = "LANGISO", table = "MYENTITY_L10N") ...

21. Assertion Fails with @ElementCollection    forum.hibernate.org

@Embeddable public class Quote implements Serializable { /** * */ private static final long serialVersionUID = -1354843737714041018L; @Column(name = "quotePrice", precision = 10, scale = 2) BigDecimal price = BigDecimal.ZERO; @Column(name = "quoteSize") int size ...

22. Wrong PK for @ElementCollection    forum.hibernate.org

Hi all, I have a wrong definition of the primary key for the table used to store the embedded components of an entity. Hibernate: 3.5.1-Final Code is: Code: @Entity(name = "A") @org.hibernate.annotations.Entity(dynamicUpdate = true, optimisticLock = OptimisticLockType.VERSION) @Table(name = "A") public class ABean { ... @ElementCollection(fetch = FetchType.EAGER, targetClass = AComponent.class) @JoinTable(name = "B", joinColumns = @JoinColumn(name = "aid", nullable = ...

23. @ElementCollection Repeated column in mapping for collection    forum.hibernate.org

... not important Spring's complains ... Caused by: javax.persistence.PersistenceException: [PersistenceUnit: phibase.schema] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:911) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ... 47 more Caused by: org.hibernate.MappingException: Repeated column in mapping for collection: org.phibase.database.schema.ReferenceGeneProduct.joinedReferenceGene column: referenceGeneProductID at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:341) at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:364) at org.hibernate.mapping.Collection.validate(Collection.java:321) at org.hibernate.mapping.Set.validate(Set.java:42) at org.hibernate.cfg.Configuration.validate(Configuration.java:1336) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1835) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902) ... 52 more

24. @ElementCollection + Enumerated    forum.hibernate.org

I'm using ElementCollection annotation, but i can't make it work, looks like hibernate is not processing it. My code @Entity(name = "user") public class User implements Serializable { private static final long serialVersionUID = 5791136125077815304L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String username; private String password; private String mail; private Date createdOn; @ElementCollection @Column(name = "authority") @CollectionTable(name = "user_authority", ...