hibernate-mapping

Overriding @Id defined in a @MappedSuperclass with JPA

流过昼夜 提交于 2019-12-05 06:20:48
I have a class AbstractEntity that is extended by all the entities in my application and basically acts as an Identifier provider. @MappedSuperclass public class AbstractEntity implements DomainEntity { private static final long serialVersionUID = 1L; /** This object's id */ @Id @GeneratedValue(strategy = GenerationType.AUTO) protected long id; @Temporal(TemporalType.TIMESTAMP) @Column(name="creation_date", nullable = false, updatable=false) private Date creationDate = new Date(); /** * @return the id */ public long getId() { return this.id; } /** * @param id the id to set */ public void setId

Specify default value in Hibernate's XML configuration file

非 Y 不嫁゛ 提交于 2019-12-05 04:14:32
I'm configuring Hibernate via the mapping configuration file. <class name="Person" table="person"> <id name="id" column="id" type="long"/> <property name="name" column="name" type="string"/> <property name="age" column="age" type="integer"/> </class> How do I set age to be nullable and default to null? <property name="age" type="integer"> <column name="age" not-null="false" default="null" /> </property> 来源: https://stackoverflow.com/questions/10610211/specify-default-value-in-hibernates-xml-configuration-file

Mapping problem with Hibernate

 ̄綄美尐妖づ 提交于 2019-12-04 22:21:03
问题 I am new to hibernate and i am having trouble with specifying the location of the mapping file in hibernate.cfg.xml file. I have created an Event object in org.hibernate.tutorial.chapter1.domain.Event.java package with its corresponding Event.hbm.xml file in the same location. I am trying to specify the location in the hibernate.cfg.xml mapping tag but I am getting an InvalidMappingException (). I have added to the post: the exception, the mapping from the mapping file and the project file

Hibernate Validator - Add a Dynamic ConstraintValidator

寵の児 提交于 2019-12-04 21:09:09
问题 After learning about Hibernate Custom Validators, it has given me an interest in one topic, could I possibly create one base annotation wherein I could set which Validator to use? @Target({ ElementType.FIELD }) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = validator().class) public @interface CustomAnnotation { public String message(); Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; Class<? extends ConstraintValidator<? extends CustomAnnotation

Intercepting NHibernate persistence operations on ICollection's properties (many associations)

↘锁芯ラ 提交于 2019-12-04 20:27:09
I would like to intercept persistence operations over collection properties, decide by myself if it can be synchronized with database, and call a procedure when a persistence is decided to occur over all collection at once and not by each element. How to do that ? These collection properties are usually mapped with one-to-many or many-to-many associations. So, when we have something like this: myEntity.List.Add(new Item()); myEntity.List.Add(new Item()); ... session.Save(myEntity); For a mapping having two classes (entities) and an unidirectional many-to-many association, I would like to have

Hibernate unidirectional OneToMany delete violates constraint ( optional=false at parent side?)

喜欢而已 提交于 2019-12-04 19:29:03
I use Hibernate 3.6 and I have something like this: @Entity public class Parent { @OnyToMany( fetch = FetchType.LAZY, cascade = { ascadeType.ALL } ) @Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE ) @JoinColumn( name="Parent_ID" ) public List<Child> getChildren() { return children; } public void setChildren( List<Child> children ) { this.children = children; } private transient List<TitleMetadataCategory> children; ... } @Entity public class Child { .... } Association is unidirectional for several reasons and I don't want to change it

one-to-one mapping is not working with 2nd-Level-Cache

只谈情不闲聊 提交于 2019-12-04 18:21:24
I have declared the fallowing mapping with NHibernate3: with FluentNHibernate public class ActivityMap : ClassMap<Activity> { public ActivityMap() { this.Table("Activity"); this.Cache.ReadWrite(); this.Version(x => x.ObjectVersion); this.Id(x => x.Id).GeneratedBy.Assigned(); // snipp this.HasOne(x => x.AppointmentRecurrence).Cascade.Delete(); } } public class AppointmentRecurrenceMap : ClassMap<AppointmentRecurrence> { public AppointmentRecurrenceMap() { this.Table("AppointmentRecurrence"); this.Cache.ReadWrite(); this.Version(x => x.ObjectVersion); this.Id(x => x.Id).GeneratedBy.Foreign(

Hibernate: Why is binding for a field similar weather explicit @JoinColum annotation is used or not?

孤街醉人 提交于 2019-12-04 16:44:11
Is @JoinColum implicitly specified when we use any association type annotation like @OneToOne , @OneToMany , etc. Here is snippet from Student entity in association with Laptop entity Case 1) Without using explicit @JoinColum @OneToMany(cascade=CascadeType.ALL) private List<Laptop> laptops=new ArrayList<Laptop>(); Case 2) Using explicit @JoinColum @OneToMany(cascade=CascadeType.ALL) @JoinColumn private List<Laptop> laptops=new ArrayList<Laptop>(); When I check DEBUG both cases have "almost" similar Binding , i.e something like below. 1) So could I assume @JoinColum is implicitly specified when

Map a composite key inside a composite key hibernate xml

心已入冬 提交于 2019-12-04 16:25:12
This is what I would like to do, map an object to another table that has the same primary keys. The below is an example, basically I have one object with a composite key that has a composite key for ANOTHER table, but I don't know how to include both in order to create the proper object key. I highlighted the row that is wrong, it only includes one of the properties for the key. <class name="BusinessRuleObject" table="BUSINESS_RULE_OBJECTS" schema="DB"> <composite-id name="businessRuleObjectId" class="BusinessRuleObjectId"> <key-property name="sameIdCode" column="ID_CD" /> **<key-many-to-one

How to retrieve a member object of a class using Hibernate?

痴心易碎 提交于 2019-12-04 13:31:42
Using following code I can successfully retrieve address fields of a user, to do that I need to define all its fields using Projection. Imagine address has 100 fields, in this case I have to define all of them. I am wondering if I can return just address object of customer without defining all its fields in Proposition? I know I can retrieve id of address and use that to retrieve its object, but I am wondering if there is ano other method rather than this or defining all its fields. Hibernate ..... Criteria cre = session.createCriteria(User.class, "user") .createAlias("user.address", "addr");