hibernate-mapping

How can I prevent Hibernate from updating NULL values

半世苍凉 提交于 2019-12-20 09:48:26
问题 Is there a setting in hibernate to ignore null values of properties when saving a hibernate object? NOTE In my case I am de-serializing JSON to a Hibernate Pojo via Jackson. The JSON only contains some of the fields of the Pojo. If I save the Pojo the fields that were not in the JSON are null in the Pojo and hibernate UPDATES them. I came accross the setting updateable=false , but this isn't a 100% solution. http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity

Why am I getting Mapping Exception?

你说的曾经没有我的故事 提交于 2019-12-20 06:29:42
问题 I am getting : org.hibernate.MappingException: Foreign key (FKBB979BF4266AA123:address [a_id])) must have same number of columns as the referenced primary key (address [p_id,a_id]) as I try to run the following (though incomplete) snippet : public static void main(String args[]) { Configuration config = new Configuration().configure(); SessionFactory sessFact = config.buildSessionFactory(); Session sess = sessFact.openSession(); Transaction trans = sess.beginTransaction(); } The hibernate

How To Use Sequence In Hibernate As A Property In XML Mapping

梦想的初衷 提交于 2019-12-20 02:05:11
问题 How do I use a sequence in Hibernate XML mappings? The documentation mentions the <generator> element. However, I want the sequence to be a column instead of an ID. 回答1: I know when using Hibernate with Oracle the id in the mapping file is defined something like: <id name="id" column="item_id"> <generator class="sequence"> <param name="sequence">NAME_OF_YOUR_SEQUENCE</param> </generator> </id> You can also specify the generator class as "native", which is handy if you then switch to an auto

Failed to create sessionFactory object.org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml

不想你离开。 提交于 2019-12-19 12:05:32
问题 Here is my Employee.hbm.xml <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package = "com.demo.hibernate.beans"> <class name="Employee" table="employee"> <meta attribute="class-description"> This class contains the employee detail. </meta> <id name="id" type="int" column="id"> <generator class="native"/> </id> <property name="firstName" column="first

hibernate and generic field mapping

梦想的初衷 提交于 2019-12-19 11:05:27
问题 I want to map a generic field in a superclass with Hibernate. My mother class is : @Entity @Table(name = "ParameterValue") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "parameterType", discriminatorType = DiscriminatorType.STRING) public abstract class ParameterValue<C> { private C value; /* HELP NEEDED HERE */ public C getValue() { return value; } public void setValue(C value) { this.value = value; } } One subclass : @Entity @DiscriminatorValue(value =

How to map many value type collections to one single table in Hibernate?

穿精又带淫゛_ 提交于 2019-12-19 10:15:33
问题 I am tring to map many value-type sets in hibernate to one table for performance reasons. First I did put them all in their own table which led to too many joins. I have a Categories class that contains many components with a bunch of sets and then I map them to a single table through subclasses by using the entity-name and discriminator. See below for the mapping snippet. This works fine, but because the single table that contains all the sets, it's hard to automatically remove a set when a

Hibernate Bidirectional ManyToMany delete issue

蹲街弑〆低调 提交于 2019-12-19 08:59:48
问题 In my project I have entities for users and companies: @Entity @Table(name = "users") public class UserDetails { @Id @GeneratedValue @Column(name = "user_id") private int id; @Column(name = "first_name") @NotEmpty @Size(min = 2, max = 20) private String firstName; @ManyToMany(cascade = CascadeType.REFRESH) @JoinTable(name = "users_companies", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "company_id")) private Set<CompanyDetails> userCompanies = new

Specifying a primary key on @ElementCollection

為{幸葍}努か 提交于 2019-12-18 21:59:10
问题 So, there is that behavior with innodb that can cause problem if some tables lack of primary key. So with Hibernate, I am looking for a key to specifies a primary key on a @ElementCollection table with a Set as the underling data structure. I found a way to have a primary key with a map, but it is kind of weird because I do not need a map. I also found an answer related to @Embeddable, but I do not need that kind of complexities. I am using a Set or Set as the data structure in my entities.

org.hibernate.MappingException: Unable to find column with logical name

蹲街弑〆低调 提交于 2019-12-18 19:04:06
问题 hi my tables are as follows: 1- medical_company : medical_company_id foreign key on account_entity table account_entity_id column (not a pk) column1 column2 column3 2- account_entity : account_entity_id (pk) column1 column2 column3 3- person: person_id (pk) column1 column2 column3 4- employee_company: company_id foreign key on medical_company table on medical_company_id employee_id foreign key on person table on person_id column1 column2 ENTITIES: 1- MedicalCompany: @SuppressWarnings("serial"

How to use a child association property as a Map key in JPA parent entity

被刻印的时光 ゝ 提交于 2019-12-18 07:02:29
问题 I'm having two entities Car and CarDescription where CarDescription is depending on another foreign key from the table Language . What I' trying to accomplish is to have a HashMap in Car such that whenever I'm having a Car entity-object I am able to access all descriptions from the language id. Entity Car.java @Entity @Table(name = "Car") public class Car extends AbstractTimestampEntity implements Serializable { private static final long serialVersionUID = -5041816842632017838L; @Id