hibernate-annotations

How to create hibernate composite key using annotations

雨燕双飞 提交于 2019-12-28 05:07:09
问题 I am trying to use hibernate annotations to insert data to a MySQL database table which doesn't have a primary key defined. However the fact is 2 fields of that table together are unique in the table.how can i achieve the same using hibernate annotation?. here is my code.. @Entity @Table(name = "RolesMenuItems") public class RolesMenuItems { @Column(name = "RoleID") private String roleID; @Column(name = "MenuItemID") private String menuItemID; /*setter getter methods */ } 回答1: You can use

Confusion in giving hibernate association annotation

风格不统一 提交于 2019-12-25 09:16:06
问题 I have a parent object lets say Campaign and child object Ad Segments. Campaign is holding one to many relation with Ad Segments. following is the annotations I defined. class CampaignModel { OneToMany(mappedBy="campaign", cascade=CascadeType.PERSIST, fetch = FetchType.EAGER) @Setter @Column(updatable=false) private List<AdSegmentModel> segments; ..... } class AdSegmentModel { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="campaign_id") @Getter @Setter private CampaignModel campaign;

maven-compiler-plugin 3.6.0 doesn't compile generated sources from annotations

混江龙づ霸主 提交于 2019-12-24 20:05:07
问题 We just upgraded our JBoss from 6.1.0 to Wildfly 10.1, and made a variety of associated upgrades to modules and artifact versions and so on. In one module this caused our cobertura compiles to fail with a compiler error. I found IllegalStateException in Hibernate metamodel generation with maven and upgraded to maven-compiler-plugin 3.6.0 (from 3.1). This seemed to resolve my problem, but only on a local basis. I can compile the module for cobertura, but it turns out to cause a new problem.

Can an INITIALLY DEFERRED constraint be defined using a Hibernate annotation?

谁说我不能喝 提交于 2019-12-24 15:56:12
问题 I have a table with a column that has a UNIQUE constraint. I want the constraint checking to be deferred to commit time. If I create it using Postgres SQL like this (many columns omitted): CREATE TABLE instrument ( id bigint NOT NULL, name character varying(255) NOT NULL, CONSTRAINT instrument_pkey PRIMARY KEY (id), CONSTRAINT instrument_name_key UNIQUE (name) DEFERRABLE INITIALLY DEFERRED ) Then everything works as expected. If I define it to Hibernate like this: import java.io.Serializable;

Disable Lazy Loading in Hibernate

可紊 提交于 2019-12-23 07:50:39
问题 How do I disable lazy loading in Hibernate? I am using persistence annotations, not an hbm xml file. I am fetching a single object by ID and want all properties loaded. The session is closed before I use the object. Thanks! 回答1: You need to annotate the properties that you want non-lazy loaded with FetchType.EAGER @ManyToOne(fetch = FetchType.EAGER) You see, it isn't the object that you are loading that is lazy loaded. Rather, that object's associations are lazy, and you need to tell them not

org.hibernate.AnnotationException: No identifier specified for entity: com.ubosque.modelo.Ciudadano

江枫思渺然 提交于 2019-12-23 05:30:36
问题 I get this error: org.hibernate.AnnotationException: No identifier specified for entity: com.ubosque.modelo.Ciudadano my class: @Entity @Table(name="ciudadano") public class Ciudadano implements java.io.Serializable { private static final long serialVersionUID = 1L; private int id; private String nombre; private String apellido; @Column(name="fecha_nac") private Date fechaNac; @Column(name="lugar_nac") private String lugarNac; private String direccion; private String telefono; @Column(name=

spring 3.1.0 Release Hibernate 4.1.2 Final - Database configuration via annotation how to set properties

帅比萌擦擦* 提交于 2019-12-23 02:44:08
问题 I am using configuration as in the code listed below. auto create/drop function seams not to work as it should (it does not create/maintain tables in the database (dataSource.setConnectionProperties(hibernateProperties());)) (It works when table is already created in the DB? I think that properties are not taken into consideration here?), Config package com.parisibw.persistance; import java.util.Properties; import javax.sql.DataSource; import org.hibernate.SessionFactory; import org

On Delete Cascade Hibernate ManyToMany

ε祈祈猫儿з 提交于 2019-12-22 00:14:31
问题 I want UserAcounts to be able to have many UserGroups.And All Groups can have many Users.And there is a join table.I want the releation between useraccount and usergroup in join table to be deleted when a useraccount is deleted. Actually i want to use "on delete cascade".In ManyToMany relation I coulndn't run it unfortunately.I've tried so much thing but no solution I've found. Note:I just want Relation to be deleted with on delete cascade is it possible is there a way to do that? Here is my

Hibernate Polymorphism.EXPLICIT annotation doesn't work?

懵懂的女人 提交于 2019-12-21 17:22:36
问题 I know there are some post about this, but they are about a year and no response. Actually we are using Hibernate 4.2.1.Final over PostgreSQL 8.4. We have two entitys like this Entity A (Top Hierarchy Class) @Entity @Inheritance(strategy = InheritanceType.JOINED) @Polymorphism(type = PolymorphismType.EXPLICIT) public class A { @Id @GeneratedValue private Long id; public A() { } public A(Long id) { super(); this.id = id; } // Setters, getteres, hashCode and equals } Entity B (Subclass) @Entity

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

风格不统一 提交于 2019-12-20 12:15:56
问题 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