hibernate-annotations

Hibernate Annotation for Entity existing in more than 1 catalog

那年仲夏 提交于 2019-12-03 13:59:22
问题 I have a Person entity mapped by Hibernate to a database table in a database catalog "Active". After a period of time, records in this database table in the "Active" catalog are archived/moved to an exact copy of the table in a database Catalog "History". I have the need to retrieve from both the Active and History Catalogs. Is there a better way to model this with Hibernate annotations than making an abstract class that 2 classes extend from. This is what I have now. @MappedSuperclass public

Integrity constraint violated just when I commit the transaction

江枫思渺然 提交于 2019-12-03 13:52:57
问题 I'm using Hibernate 4.0 Final and ojdbc6 to develop my web application. Everything is ok except when I try to insert a new parent/child relationship. First of all, these are the entities: @Entity @Table(name = "EMPLOYEE") public class Employee implements Serializable, Cloneable { @Id @SequenceGenerator(name = "seq", sequenceName = "P_SEQ") @GeneratedValue(generator = "seq") @Column(name = "ID_EMPLOYEE") private long idEmployee; ...... @OneToMany(cascade = CascadeType.ALL, fetch = FetchType

Hibernate: OneToMany save children by cascade

走远了吗. 提交于 2019-12-03 08:40:42
问题 In the class Parent there is a list List. When the parent is saved the children which have been added or changed shall be save / updated by hibernate. I've found many explanations on this, however, I just don't get it to work. Parent.class try A @Entity public class Parent { // id and other attributes @OneToMany(mappedBy = "parent") @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.ALL) protected List<child> children; Parent.class try B @Entity public class Parent { //

hibernate one to many using a join table, and hibernate annotations

独自空忆成欢 提交于 2019-12-03 07:16:33
I want do a one-to-many relationship between two tables using a join table. This is why I want to use a join table: Hibernate unidirectional one to many association - why is a join table better? Why is it recommended to avoid unidirectional one-to-many association on a foreign key? Finally, I want to use Hibernate annotations to perform this. I found some examples to do this using xml mapping but nothing with annotations. I believe this would be how the tables need to be created CREATE TABLE `PRODUCT` ( `PRODUCT_ID` BIGINT PRIMARY KEY AUTO_INCREMENT ); CREATE TABLE `PARTS` ( `PART_ID` BIGINT

how to make two column as a primary key in hibernate annotation class

我们两清 提交于 2019-12-03 06:19:08
问题 This is my annotation class and i want userId and groupId column both as primary key. I have found more questions (Question) about this, but didn't found relevant answer. I have less reputation, so I am not able to comment on posts, So I am putting my question here. This is my code.. import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id

How to map a Map<String,Double>

别说谁变了你拦得住时间么 提交于 2019-12-03 06:16:49
问题 I tried @ManyToMany(cascade = CascadeType.ALL) Map<String, Double> data = new HashMap<String, Double>(); but it produces the error : org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.company.Klass.data[java.lang.Double] at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1016) at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:567) at org.hibernate.cfg

How to avoid creating a new row if similar row exists?

梦想的初衷 提交于 2019-12-03 02:26:53
I need to configure hibernate to avoid creating duplicate rows, (although the row exists it creates a new one, and since only one filed is set it set all the rest to NULL) Lets say I have a row as following id des index age 1 MyName 2 23 Although I just set MyName as des and it already exists in the Name table hibernate create a new row as following id des index age 1 MyName 2 23 2 MyName Null Null << new row with null values will be created rather than updating the previous one When I want to sa . So I have added the following annotation to my class but it crossed the Entity, and

HiLo generator strategy not working

一笑奈何 提交于 2019-12-02 23:17:33
I am new to hibernate. What I am trying to do is use @CollectionId to generate an identifier for my Address class. I have used Collection interface for this. However when I use @GenericGenerator and set strategy to hilo, it throws an Exception. Here's my code: @Entity @Table(name = "USER_DETAILS") public class UserDetails { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int userId; private String userName; @ElementCollection @JoinTable(name="USER_ADDRESS", joinColumns=@JoinColumn(name="USER_ID") ) @GenericGenerator(name = "hilo-gen", strategy = "hilo") @CollectionId(columns =

Hibernate: OneToMany save children by cascade

落爺英雄遲暮 提交于 2019-12-02 22:33:19
In the class Parent there is a list List. When the parent is saved the children which have been added or changed shall be save / updated by hibernate. I've found many explanations on this, however, I just don't get it to work. Parent.class try A @Entity public class Parent { // id and other attributes @OneToMany(mappedBy = "parent") @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.ALL) protected List<child> children; Parent.class try B @Entity public class Parent { // id and other attributes @OneToMany(mappedBy = "parent", cascade = { javax.persistence.CascadeType.ALL }

how to make two column as a primary key in hibernate annotation class

笑着哭i 提交于 2019-12-02 19:43:22
This is my annotation class and i want userId and groupId column both as primary key. I have found more questions ( Question ) about this, but didn't found relevant answer. I have less reputation, so I am not able to comment on posts, So I am putting my question here. This is my code.. import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.annotations.NaturalId; @Entity @Table(name=