Map 1 « Map « JPA Q&A

1. JPA mapping interfaces

I am having trouble creating a mapping when the List type is an interface. It looks like I need to create an abstract class and use the discriminator column is this ...

2. Hibernate one to zero or one mapping

I'm trying to map a one to "zero or one" relationship in Hibernate. I think I may have found a way using a many-to-one.

class A {
  private ...

3. Can hibernate map EnumTypes with whitespaces?

Having a hibernate mapping a legacy database I want to use EnumTypes to map certain columns that contain string constants with whitespace to some Enum class. The mapping:

@Table(name = "OPERATOR")
public class Operator ...

4. hibernate one to one mapping example

i have 2 tables table 1) cid jobtitle 2) pid jobspecif i want that pid show be forign key in table1 can anyone provide me hibernate ...

5. hibernate: Is this mapping allowed?

public class A {
    private HashSet<Foo> fooList = new HashSet<Foo>();
where class Foo is nothing special, just implements Serializable. Essentially I want ...

6. hibernate mapping class

I have a project which it's domain contain following classes:

And My database also has these tables:
and the classes which hibernate makes for above tables has same name of them. Should I use ...

7. A Stackoverflow mapping (Hibernate)

Suppose a mapping like this one

public class User {

    private Integer id

    private List<Info> infoList;    


8. How do i create this many-to-one mapping using JPA?

I'd like to achieve the following schema:

Table A:
(other columns)

Table B:
(other columns)


9. Check invariants in hibernate mapped classes

One challenge using hibernate is that manged classes have to have a default constructor. The problem is that there is no explicit point where the class is initialized and invariants can ...

10. Hibernate Mapping Conditional Many-To-One

I have to map a lecagy database for read-only purposes that contains the following structure:

Table MAIN: 
id productId productType

id description_a

id description_b

id description_c
Depending on the value ...

11. Hibernate mapping

I got a table with a PK and a value "country", all my labels are definied in another table which has composite-ids. Does anyone has an example for me how I can ...

12. Breaking up a large Hibernate class

I have a Hibernate class which is essentially just a wrapper around loads of collections. So the class is (massively simplified/pseudo) something like:

public class MyClass {


13. hibernate::map maping

I have some class C that contains Map<A, Set<B>>, where A and B has long id and mapped in tables a and b. I want do some mapping of C into ...

14. Completely evicting Maps from Hibernate PersistenceContext

When I create or load an object with a simple HashMap that uses persistable objects for both keys and values and pass that object to evict(), the evict is only cascaded ...

15. How to map these classes with Hibernate?

Suppose I've these 2 classes:

class A{

    B ref1 = null; //Can both be null
    B ref2 = null;


class B{

I'm omitted the ...

16. Confusions in hibernate mappings

Hi i am new to hibernate technology and i have few issues. Suppose if there are two tables. For Example:



17. Hibernate Map Mapping Problem

Hi I am trying to Persist a Map in Hibernate as follows:

public class Product{
 private Map<Company,ProductCompany> productCompanies=new HashMap<Company,ProductCompany>();


public class Company{
 private int id;
public ...

18. How to read Hibernate mapping

I need to know which physical column is associated to a persistent's attribute. e.g. Class LDocLine has this attribute

  private Integer lineNumber;
which is mapped in hibernate like this :

19. Map denormalized hibernate

I have a Summary class which contains a list of Qualities. A Quality contains a String name and int value. This data is stored in a denormalized db structure, one table ...

20. Hibernate Bi- Directional many to many mapping advice!

i woundered if anyone might be able to help me out. I am trying to work out what to google for (or any other ideas!!) basically i have a bidirectional ...

21. What is the "owning side" in an ORM mapping?

I'm new to JPA. Now I have a question: what exactly does the owning side mean? I only have a rough idea of it. What is an explanation with ...

22. How to map XMLType with JPA/Hibernate

How to persist XMLType column via JPA/Hibernate? As per oracle documentation, there are two ways in declaring storage clause for XMLType. They are, LOB and Object-Relational. I dont want to go ...

23. Liquibase diffChangeLog against a Hibernate mapping definition

This question is related to "Hibernate using JPA (annotated Entities) and liquibase". I was actually wondering what to expect when doing a Liquibase diff against a Hibernate mapping definition. What it seems ...

24. Hibernate Mapping a Map

Coming from NHibernate, I've tried to do something like this in Java (first example): I have the following code:

public class Box implements Serializable {
  private Long boxId;
  private ...

25. Hibernate mapping for one-to-one

I have two classes binded mapped with Hibernate and I can't figure out the configuration to map a Drug entry to my PrescribedDrug class.

public class PrescribedDrug implements Serializable {


26. Hibernate one to many mapping

I have two tables:

<class name="Content" table="language_content" lazy="false">
        <key-property name="contentID" column="contentID"/>  

27. Hibernate many-to-many mapping

I am one of hibernate user in Australia. Recently, I have been dealing with hibernate many-to-many mapping and not going well though. I got in trouble with "join/associate table with extra columns ...

28. How to map derived identities in hibernate 3?

I have the following situation:

class A{ 
  @SequenceGenerator(name = "SEQ_AID", sequenceName = "SEQ_AID")
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_AID")
  private Long aId;

29. Hibernate: mapping many-to-many to Map

I am developing an application which deals with two following entities: Products (let's name it as X, Y, Z) and Materials (a, b, c, ...). It's known that every product has ...

30. JPA/Hibernate: What use is an ORM (Hibernate) when it doesn't get all JPA mappings right?

I've played a lot with Hibernate and JPA mapping in the last couple of months/weeks. My DB uses composite primary keys and I've reported approximately 10 to 15 Hibernate and 5-10 ...

31. Problems mapping UUID in JPA/hibernate

According to the documentation, hibernate 3.6 should have support for the java.util.UUID type. But when I map it like:

@Id protected UUID uuid;
I get the following exception:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean ...

32. Mapping EnumSet in Hibernate

How to store EnumSet in the DB (using Hibernate)?

public class A
 public static enum SOME_ENUM { A, B, C };

 private EnumSet<SOME_ENUM> myEnumSet = EnumSet.of(SOME_ENUM.A, SOME_ENUM.B);

If I try to ...

33. How to map a Map of Sets in JPA

Is there a way in JPA to map an attribute with type Map<String, Set<Address>> Given the following classes:

class Company {
  int id;
  Map<String, Set<Address>> addresses; // Key is the country ...

34. one to many and many to many mapping in hibernate

one to many and many to many mapping in hibernate. What does this mean.

35. Hibernate Mapping Question

I am trying to learn Hibernate and I could create some simple CRUD operation using a Single Class and Single Table. I am just reading the Hibernate Doc and some online ...

36. Hibernate One to One Mapping

I have two class

Class Item
   private Auction CorrespondingAuction;

Class Auction
    private Item CurrentItem;
Can someone tell how to set this one to one mapping in XML, it must ...

37. Question about hibernate mapping

I am trying to setup a Many-To-Many relationship using annotations. here are my entities

public class Publisher{

38. Hibernate Mapping Question

i am trying to map some classes using some hibernate and arrived at a case where i am unable to find the best way to achieve the solution. i have three classes ...

39. Hibernate mapping one-to-many problem

I am not very experienced with Hibernate and I am trying to create one-to-many mapping. Here are relevant tables: alt text And here are my mapping files:

<hibernate-mapping package="com.xorty.mailclient.server.domain">
  <class name="Attachment" ...

40. cyclic reference problem in hibernate

While learning hibernate i came across a situation where it seems Hibernate is having cyclic reference and i am clueless how to come through this situation. i have two classes a ...

41. many to one problem

i have this error for some hours now and i don't get it anymore. It's a project with Spring 2.5 and hibernate3. I have tried with declaring a project object in ...

42. Hibernate mapping problem

I have some objects mapped via hibernate. A has one B B has many C I create B, give it a list of Cs, and set the B in A. Save it and ...

43. Hibernate Mapping

I have two tables, intially i have n't define any kind of relation ship between two tables. after inserting data into tables then, there is possibilty of relation ship may existed two ...

44. get hibernating mapping from application code

Is there a way to get the hibernate mapping from within my application code? for example, for the below mapping, I want to return createdDate given created_date from my application.


45. Hibernate mapping confusion

The below definition is taken from Hibernate association mapping tutorial here Each book is related to one publisher while one publisher may publish many books. I'd represent the above definition the ...

46. DO i need to put mapping in hibernate config

On internet tutorial says that i have to add

<mapping class="com.vaannila.student.Student" />
<mapping class="com.vaannila.student.Phone" />
in the hibernate config file But i am using annotations and in one example which i tested i didn't used ...

47. JPA Map of Maps

I have a data structure that boils down to:

class StylesheetUserPreferencesImpl {
    long id;
    String desc;
    Map<String, Map<String, String>> nodeAttributes;
To try and make ...

48. why the one-to-one undirectional mapping exist?

I am learning hibernate,and I am confused by the one-to-one undirectional mapping. For example: one wife for just one husband and vice versa. The

public class Wife {
    private int ...

49. Mapping problem with Hibernate

I am new to hibernate and i am having trouble with specifying the location of the mapping file in hibernate.cfg.xml file. I have created an Event object in package with its ...

50. Problem using Hibernate CompositeUserType

I am trying to use HibernateCompositeUser type to handle i18n specific data in my application. i am trying to use the below approach. I have a table named master table which contains all ...

51. Hibernate Mapping Scenario

Consider the following scenario.We have three objects.

property A
property B
property C

property D
property E
property F

property G
property H
property I
These objects are my business objects. Now I have two tables.
Table 1 has[A,B,C,F,I]
Table 2 has [A,B,C,E,H]
So ...

52. Hibernate mapping problem one-to-one/many-to-one

I'm facing a problem using Hibernate. I have 3 tables: tb_user, tb_book, tb_lending. In the tb_lending, I have the following fields:

  • id_lending - int(11) - primary key
  • id_user - int(11) - foreign key ...

53. best latest Hibernate book

Which is the latest hibernate book that includes information about hibernate 3 and also the latest JPA specification.

54. Hibernate mapping

There are two objects, parent and child Both parent and child implement colour Child and Parent is mapped by one to many relationship. However, only parent map to colour column, where colour column only ...

55. Hibernate marker interface mapping using jpa

Hi I am new to hibernate and am facing problem in mapping marker interface. I have a marker interface.

    public interface Item{}
Then there are two classes which implement ...

56. How to add a "where" to Hibernate many-to-one?

I currently have a many-to-one relationship set up from class Exp to class Fin like this: From Exp.hbm.xml:

<many-to-one not-found="ignore" cascade="none" update="false" insert="false" 
unique="false" class="model.Fin" name="Fin"
column="SAK_EXP" property-ref="SakTrans" />
What I need to do is ...

57. Hibernate strange createAlias bahaviour

I'm getting a very strange behaviour from Hibernate. If I execute the following query, everything works as expected:

Criteria crit = session.createCriteria( Message.class )
    .add( "sequenceReceived", Long.valueOf( 10 ) ...

58. Hibernate: how do you set up a simple uni-directional one-to-one mapping?

I've followed the hibernate documentation to the letter (, but handling the one-to-one mapping still seems cumbersome. Please let me know that I've misunderstood something here, and there's ...

59. Hibernate: Problem with mapping

I have a problem with hibernate. ((( !!! Image with Database Schema !!! Mapping (for getter's/setter's i use lombok)

@Table(name = "users")
public @Data class User

// Base Mapping

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id")
@Getter @Setter Long ...

60. how to map a LinkedHashMap with Hibernate?

I would like to map a LinkedHashMap with Hibernate (annotation driven). I know the property @MapKey and @IndexColumn, but can I used both to map a linkedhashmap with basics strings ? Please don't ...

61. One to many mapping with many possibilities

I'm trying to persist my data but am having trouble coming up with a schema that will work for hibernate in a sane way I have two objects: a channel and user. ...

62. designing classes and hibernate mappings

while going through code in some hibernate books ,I noticed some strange things about entity classes. For example a Customer has an Address.The mapping given is

public class Customer implements Serializable {

63. Hibernate Mapping

i want write a mapping File for following Class, but i dont know how.

public class TwoDimHashMap<K1, K2, I> {
   private final Map<K1, Map<K2, I>> main;
   public TwoDimHashMap() ...

64. Hibernate: mapping two classes to a common third class

I am searching for the correct mapping of a many-to-one relationship of two classes pointing on a third one. An example is shown in the image below: enter image description here In ...

65. Hibernate Master-SubDetails Mapping

I'd like to explore hibernate and used it in my project instead of JDBC. My table design is higly normalized. Suppose, I have this use case: Each insurance applied by a customer has one ...

66. Hibernate Mapping issue

I've 3 tables: A, B and C. A holds a one-to- many relation with B and B holds a one-to-one relation with C. When I do a, a row will ...

67. Hibernate one-to-many mappings

I am new to Hibernate. In my application I am maintaining a one-to-many mapping for a List. The mapping in the hbm file looks like this:

<list name="list1" lazy="false" inverse="true" cascade="all, ...

68. Hibernate mapping issue

very simple problem here... but I can't work it out. I have a simple class from my model

public class Catalogazione extends ModelEntity {

private String nome;
private int showBox;

public int getShowBox() {

69. hibernate mapping "rules"

Is it possible to do a one-to-one mapping to a property, not using primary keys? Basically, what i want to do is to have a property in my "Parent" class, which ...

70. Hibernate one-to-one and one-to-many

I currently have a one-to-many relation between 2 table: I have:

Table A (id, ...)
Table B (tableAId, ...) (has no id of it's own).
In the mapping this is done using <list>. The issue ...

71. What is the need for many-to-one mapping in hibernate?

Why don't we just specify the table name and column name? How specifying many-to-one helps in generating query?

72. Hibernate @DiscriminatorValue not picked up

I have the following hierarchy:

@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
class Change {
  @Column(name="type", nullable=false, insertable=false, updatable=false)
  String _type;

  @JoinColumn(name = "user_id")

73. jpa result-set-mapping throw NPE

I can't map query result to POJO. JPA executes query ok (it trace in logs) but in mapping process throws a NPE. What is wrong? NPE:

at org.eclipse.persistence.queries.EntityResult.getValueFromRecord(
at org.eclipse.persistence.queries.ResultSetMappingQuery.buildObjectsFromRecords(
at org.eclipse.persistence.queries.ResultSetMappingQuery.executeDatabaseQuery(
at org.eclipse.persistence.queries.DatabaseQuery.execute(
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery( ...

74. Best practice for testing Hibernate mappings

I am wondering what people have found their best practice to be for testing Hibernate mappings and queries ? This cannot be done with Unit Testing, so my experience has been to ...

75. Hibernate - proper one-to-one mapping

How should I map one-to-one association between A and B classes in case != (as hibernate offers for one-to-one association) and I want to have an association like A.b_id ...

76. Abstraction over different OR Mapping frameworks

The Data access layer of my product today uses Hibernate as the OR mapping framework.In future would like to use other frameworks like iBatis.

  1. What is the best way to design such ...

77. Hibernate BatchUpdateException

I am trying to insert some data using hibernate but facing some issue while achieving this.i am using following configurations

-Hibernate 3.6.8 
-MySQL 5.5.17 
I am using org.hibernate.dialect.MySQL5InnoDBDialect as my dialect i have ...

78. How to do this hibernate mapping?

I am newbie to hibernate world, so sort of confused in writing mapping file in following condition. I have following class which I want to persist using hibernate :

class Project {

79. hibernate mapping

If I understand you right you already have the mapping (your xml file) so you don't need to build the mapping. There are tools avaliable with Hibernate to create schema from mapping files (look at Hibernate's site for the Schema Export/Schema Update utilities. However, if you are unsure how to create a DB schema independently of Hibernate, I'd go and learn ...

80. Hibernate Mapping Question

ID is a required child node of the class element. The Hibernate docs are very insistant about proper relational identity, so it's pretty ridgidly enforced in their design. I'm not sure I understand exactly what you are trying to do though - does your application add the (not guarenteed to be unique) fields to the table, then later on you assign ...

81. Hibernate- one to many mapping problem

Hi, I have a classical bidirectional Parent Child relationship in my tables. Parent has a set of Child Objects and each Child has a reference to the Parent. This is implemented in the database tables. I used middlegen to automatically read the database schema and generate the mapping files and the POJO's. My problem was that the mappings were generated something ...

82. mapping in hibernate

Im having a bit of problems figuring out how to do the best mapping for my domain. I have a: User object that have a Bookshelf The bookshelf have Booklines that contains a reference to a Book and some other atributes I have the bookshelf because i thought it would be best to have methods there and not on the user ...

83. Hibernate mapping no good?

I am trying to run a junit test with Hibernate. When the method runs, it does not seem to find the values I have assigned to the parameters to be stored. For example: From test class: private static final int departmentId = 444; department = new Department(); department.setCity("City"); department.setState("State"); department.setName("Department Name"); department.setDepartmentId(departmentId);; mapping file:

84. hibernate mapping quiz

Hi all, I designing an app, and I have something like the code bellow, I can't find a way to map it. What I want to do I to map it all in 1 table, and I don't know if it's posible, as car 'has a' Value this should be mapped as a component, but component doesn't support inheritance, I could ...

85. special hibernate mapping

Hi, I have a special case of data model, which is the following: 1- I have a table where my entities, i.e table names are stored: CREATE TABLE [Entity_tbl] ( [id] [INT] NOT NULL , -- (PK) [name] [NVARCHAR] NOT NULL ) 2- I have a table where I store values, which it's used by any entity, for instance [Status] value ...

86. Hibernate Mapping Question

I have a question about how to solve a design problem. My application has a Java Class which is mapped twice in the XML Hibernate mapping, as a component of two distinct "parent" Classes (not "parent" in the sense of inheritance, but "parent" in the sense of that which a dependent component is dependent upon). In each case, there is a ...

87. Hibernate 2.1 mapping

hi, i am new to hibernate. i have a query. i have the following class heirarchy Interface A Class B implements A (class B is an abstract class) Class C extends B Class D extends B Class E extends B Class F extends C What will be the mapping for this if i were to use table per class hierarchy what ...

88. Hibernate: Can someone verify my mapping configuration?

I'm still experimenting with Hibernate, and I would really appreciate if someone could provide me some feedbacks on my mapping configuration. My test app has 3 database tables: PERSON, CAR and CARTYPE. The relationship between PERSON and CAR is one-to-many, and CARTYPE to CAR is one-to-many. These are my JAVA bean classes:- Person Table ---------------- LongpersonId StringpersonName Setcars Car Table ---------------- ...

89. Hibernate mapping question

Andreas, Is the cardinality between device and fault_record really 1 to many? Both tables have the same primary key, do they not? The easiest way to map this might be to ignore the relationship between fault_record and error_text. To get the error_text, get the device entity from the fault_record and then retrieve the error_text from the device. To limit the error_text ...

90. Hibernate Map mapping problem

Hi all! Hibernate newbie here, I've been using these forums over the last couple days to iron out some issues I have been having, so thanks! and thanks in advance for any help on this issue. I'm sure I am just missing something dumb I have two tables: hotel: hotel_id PK locale PK ... other fields ... hotel_images: hotel_id PK name ...

91. problem in mapping hibernate class

hi all, i am getting " org.hibernate.MappingException: Could not read mappings from resource: src/emp.hbm.xml" error. below i am pasting .CFG as well as .hbm files. can somebody please help me out. // hibernate.cfg.xml------ pwd jdbc:mysql://localhost/emp root org.hibernate.dialect.MySQLDialect //emp.hbm.xml------ ...

92. Problem with Hibernate Mapping

93. Hibernate mapping issue

I have very limited hands on Hibernate experience, so please be kind. I have a table CURRRPT -------- I_Report integer I_Remark_ID integer C_Remark_Type char(2) T_Remark varchar(80) The CURRRPT table connects to a Report table via the I_Report field and the I_Remark_ID is a generated number as there will be many rows. I have an object for the Report Table and setup ...

94. Hibernate mapping problem

Hi, i have the following DB table, very simple CLASS ------- class_id class_name STUDENT --------- student_id student_name STUDENT_STATUS -------------- student_id class_id midterm_score final_score my mapping is as follow The whole ...

95. hibernate + mapping a class more than once

Hi all! At the system that Im workin on, its necessary to map a class more than once - this means: one class -> 2 tables. I found out how to do it on My problem is: at the save operation both tables should be updated, but it successfuly happens only with the first table (declarted at my hbm.xml file). ...

97. Hibernate Mapping

98. hibernate mapping

hi friends. I have a problem in hibernate mapping between two tables. the below is the mapping file:

99. Mapping a UUID in Hibernate

Hi, I want to have a class that contains a UUID id attribute e.g. public class X{ private UUID id; public UUID getId() { return id; } public void setId(UUID id) { = id; } } My database table for X contains a VARCHAR(36) because a UUID is 32 characters long plus the 4 dashes. How can I therefore tell ...

100. One to One mapping in Hibernate 3

Hi, I am trying to write a sample for One To One mapping in Hibernate 3. Following is the scenario. I have an Employee object and a Parking Space Object. The have a one to one relation i.e., an employee will always be associated to only one parking space, that parking space should not be associated to any other employee. I ...