hibernate-annotations

Hibernate annotated many-to-one not adding child to parent Collection

柔情痞子 提交于 2019-12-09 03:32:44
问题 I have the following annotated Hibernate entity classes: @Entity public class Cat { @Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO) @Id private Long id; @OneToMany(mappedBy = "cat", cascade = CascadeType.ALL, fetch = FetchType.EAGER) private Set<Kitten> kittens = new HashSet<Kitten>(); public void setId(Long id) { this.id = id; } public Long getId() { return id; } public void setKittens(Set<Kitten> kittens) { this.kittens = kittens; } public Set<Kitten> getKittens() {

How to set hibernate.hbm2ddl.auto in Spring with Annotations and pure Java

僤鯓⒐⒋嵵緔 提交于 2019-12-08 21:26:35
问题 How would one go about setting up the following in Spring using only Java and annotations. <property name="hibernate.hbm2ddl.auto" value="update"/> I amIt should be possible and I do believe it is a lot cleaner to make projects xml free. PS: This shouldn't be important but I'm running this on Heroku. 回答1: Added this to the class where the dataSource() is and it fixed my issue. final Properties hibernateProperties() { final Properties hibernateProperties = new Properties(); hibernateProperties

Issue persisting long strings with Hibernate

a 夏天 提交于 2019-12-08 17:43:46
问题 In my web application, I have a text area whose user-filled contents are ultimately persisted to the db with Hibernate. I have been running into an issue that when the user input is beyond a certain length, the persistence fails. Is there a way to indicate through Hibernate Annotations or in the configuration that this particular field should support longer strings, and that the database column type should reflect this? Here's the exception that I'm getting: Caused by: java.sql

Hibernate @OneToOne mapping with a @Where clause

淺唱寂寞╮ 提交于 2019-12-08 17:41:59
问题 Will this work - @OneToOne() @JoinColumn(name = "id", referencedColumnName = "type_id") @Where(clause = "type_name = OBJECTIVE") public NoteEntity getObjectiveNote() { return objectiveNote; } This is what I am trying to do - get the record from table note whose type_id is the id of the current object and type_name is OBJECTIVE . I can't get the above mapping to work. What am I doing wrong here? 回答1: This just plain does not work, sorry :( You will need to do it as one to many and live with

Hibernate Annotation using base entity

☆樱花仙子☆ 提交于 2019-12-08 16:03:07
问题 In my project I have a POJO called BaseEntity as shown below. class BaseEntity{ private int id; public void setId(int id){ this.id=id; } public int getId(){ return id; } } And a set of other POJO entity classes like Movie, Actor,... class Movie extends BaseEntity{ private String name; private int year; private int durationMins; //getters and setters } I'm using BaseEntity only for using it as a place holder in some interfaces. I never have to store a BaseEntity object. I have to store only

db2 identity with hibernate configuration (SQL Error: -142, SQLState: 42612)

こ雲淡風輕ζ 提交于 2019-12-08 11:39:28
问题 Please help on DB2 identity in Hibernate annotation. Im using DB2 version 10.01, trying to insert values into the table using hibernate save() method. Id annotation: @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "stmciss_id",unique=true,nullable=false) protected int id; Hibernate configuration: <property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property> Identity creation in the schema: "STMCISS_ID" INTEGER NOT NULL

Join entity with composite key

冷暖自知 提交于 2019-12-08 10:23:30
问题 I have 2 entities for legacy db with composite keys, one of them has a composite key with @EmbeddedId annotation. // first entity @Entity public class Product { @Id private Integer productId; // lookup table contains code-description pairs @OneToOne private ProductDefects defects; //getters and setters and other code omitted } // lookup entity @Entity public class ProductDefects { @EmbededId private ProductDefectsPK id; //getters and setters and other code omitted } //composite key @Embedable

hibernate not generate auto increment constraint on mysql table

守給你的承諾、 提交于 2019-12-07 17:58:44
问题 I have been searching through different forums for the problem and had tried different solutions but i am still unable to find any correct answer for my problem. I am using hibernate4 annotations for mapping my entities. everything works fine but only auto increment key is not detected when tables are created using hibernate in mysql. i have following code: @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(unique = true, nullable = false) private int responseId; i also have

Hibernate JPA IdentifierGenerationException: null id generated for class with @embeddedid

大憨熊 提交于 2019-12-07 06:49:39
问题 I am having trouble mapping my database domain model to the program entities in one case where the entity is essentially a join table (a period) which combines two other entities (a timeslot and a day). Another entity (a lesson) then has a reference to this period entity, determining when it occurs. When I try to save a lesson with a new period using saveOrUpdate(lesson) hibernate throws an IdentifierGenerationException org.hibernate.id.IdentifierGenerationException: null id generated for

How to create meta annotations on field level?

情到浓时终转凉″ 提交于 2019-12-06 01:47:42
问题 I have this hibernate class with annotations: @Entity public class SimponsFamily{ @Id @TableGenerator(name = ENTITY_ID_GENERATOR, table = ENTITY_ID_GENERATOR_TABLE, pkColumnName = ENTITY_ID_GENERATOR_TABLE_PK_COLUMN_NAME, valueColumnName = ENTITY_ID_GENERATOR_TABLE_VALUE_COLUMN_NAME) @GeneratedValue(strategy = GenerationType.TABLE, generator = ENTITY_ID_GENERATOR) private long id; ... } Since I don´t won´t to annotate every id field of my classes that way, I tried to create a custom anotation