jpa 2.1 - How to subclass Hibernate entity class effectively replacing the parent?

Given the following scenario:A project using a frameworkThe framework defines basic entity classes (used for logging, user management etc.)The project has application specific entity classes.I want to subclass a framework class in a way that does not need changes to the framework code nor the framework specific database schema (apart from any constraints that maybe introduced by additional mappings).Here is a simplified framework class:package com.example.parent;@Entity@Table("entities")public class ExampleEntity { @Id @GeneratedValue ...Read more

eclipse mars - Getting Nullpointer exception while creating a hibernate mapping XML file?

I'm trying to create a XML based configuration for a model class. Using Hibernate XML Mapping file option from hibernate menu which comes with the JBoss Tools.But it throws NullPointerException as in the image shown below.Using: Java 8 and Eclipse Mars 4.5.2 JBoss Tools 4.3.1.FinalPlease suggest me a solution to solve this issue. Thanks in advance.//Elusive Log...Read more

hibernate mapping - How to apply the same naming strategy to @index columnList as for column?

Since one of the newer releases of the JBPM was added an indexes internal classes:@Entity@Table(name="Attachment", indexes = {@Index(name = "IDX_Attachment_Id", columnList="attachedBy_id"), @Index(name = "IDX_Attachment_DataId", columnList="TaskData_Attachments_Id")})@SequenceGenerator(name="attachmentIdSeq", sequenceName="ATTACHMENT_ID_SEQ", allocationSize=1)public class AttachmentImpl implements InternalAttachment { ... @ManyToOne() private UserImpl attachedBy; ...}attachedBy_id column from the index columnL...Read more

hibernate mapping - How can I map "insert='false' update='false'" on a composite-id key-property which is also used in a one-to-many FK?

I am working on a legacy code base with an existing DB schema. The existing code uses SQL and PL/SQL to execute queries on the DB. We have been tasked with making a small part of the project database-engine agnostic (at first, change everything eventually). We have chosen to use Hibernate 3.3.2.GA and "*.hbm.xml" mapping files (as opposed to annotations). Unfortunately, it is not feasible to change the existing schema because we cannot regress any legacy features.The problem I am encountering is when I am trying to map a uni-directional, one-to...Read more

Joining Tables with Composite Primary Keys in Hibernate hbm files

I have two table to be joined using hbm file. The scenario is as followsTable B has a composite PK.Table Ba1 (pk) a2 (pk) a3 (pk) foo bar======== Table A has a primary key and is a foreign key from Table BTable Aa1 (pk,fk) hip hop========This a one to many relation from Table A to B.Can any one help me out with the hbm file mapping?I am jotting down wot i have tried.For Table B<class><composite-id name="XXXX" class="....."> <key-property name="a1" column="a1" type="int"/> <key-property name="a2" column="a2" ty...Read more

How to map an object to contain a Map in hibernate?

Let's say I have a table 'Team' and another table 'Team Members'. Team Member has a foreign key to Team.Ideally, I would want hibernate to map my java objects such that, Team class would have a Map of Team Members. The key of the map is the name of the team member, and value is the TeamMember object.So I would want my Team class to look like this:public class Team { private Map<String, TeamMember> _teamMembers;}How do I map in my hibernate xml mapping file?...Read more

Default class for Hibernate Single Table Inheritance Scheme

I have an application that maps views into an existing Hibernate schema that makes extensive use of single table inheritance with a discriminator-value in the CLASSNAME column. What makes my situation unusual is that I do not what to support all the subclasses (discriminator-value in the Hibernate mappings) in the data, just those of interest to the application. The problem is that if the application encounters an unsupported discriminator-value, Hibernate throws a "org.hibernate.WrongClassException" because it cannot find a mapping with the re...Read more

Mapping 2 Tables with same structure in Hibernate

I have an existing application with an entity, for example Employee (Table EMP) and it is used at several places. Now after a long time, a replica (EMP_ARC) for the table EMP is created and we are supposed to refer it in certain scenarios.As the table structure is exactly same I thought of reusing the POJO declaration. But I could not find a way to reuse the same POJO for two different table declarations. (I had seen examples of XML mapping to map one POJO to multiple tables but our application is using annotations and not able to find such opt...Read more

hibernate mapping - One to many cascade All is not setting parent id while child entry insertion

I am using Hibernate 3 annotations.I have a table 'product' and child table 'product_spec' with one-to-many relation.When i do it is giving errorcould not insert: [com.xx.ProductSpec]; SQL [insert into Products_spec Column 'PRODUCT_ID' cannot be null@Entity@Table(name = "product")public class Product implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue @Column(name = "PRODUCT_ID") private Integer productId; @Column(name = "PRODUCT_NAME") private String p...Read more

jboss7.x - JBoss 7.1.1 with Hibernate 4.1.1

I was developing Application which will read the Hibernate configuration from hibernate.cfg.xml file which is under following folderJBoss7.1.1/standalone/configuration/example1/hibernate.cfg.xml<mapping resource="example1/hbm/T1.hbm.xml"/><mapping resource="example1/hbm/T2.hbm.xml"/>and all the mapping file are kept underJBoss7.1.1/standalone/configuration/example1/hbm/*.hbm.xmlBut its not working, its throwing org.hibernate.MappingNotFoundException: resource:example1/hbm/T1.hbm.xml. is their any issue with the above configur...Read more