hibernate-mapping

Hibernate ordering in sql

核能气质少年 提交于 2019-12-10 00:25:18
问题 Is it possible to sort the Set collection using hibernate, in sql without using SortedSet interface, without using @OrderBy annotation - just using criteria's addOrder. I've tried it and it adds order by clause but the set isn't sorted. I use hibernate 3.4. 回答1: NHibernate Sets don't have "order" even though the set mapping supports an order-by. See Ayende's explanation: Note that [order-by] does not work with generic sets and that in general, you don’t want to rely on those ordering

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

馋奶兔 提交于 2019-12-09 23:50:35
问题 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

Hibernate persist Map<String, String> without referencing another tables

强颜欢笑 提交于 2019-12-09 05:34:52
问题 Could you please help me to persist map of strings with Hibernate? Map values come from client and are random, so I don't want to store separate table for map's values Exception Caused by: org.hibernate.AnnotationException: Associated class not found: java.lang.String Code @Entity public class UserConfig { @Id @SequenceGenerator(sequenceName = "CONFIG_SEQ", name = "ConfigSeq", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ConfigSeq") private Long id;

javax.persistence Annotations on field, getter or setter?

≯℡__Kan透↙ 提交于 2019-12-09 05:10:38
问题 I am currently learning Hibernate and the Java Persistence API. I have an @Entity class, and need to apply annotations to the various fields. I have included in the code below all three places where they could go. Should I apply them to the field itself, the getter or the setter? And what is the semantic difference, if any, between these three options. import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Id; @Entity @Table(name = "song") public class Song

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

How to retrieve all records that exists in a specific relationship?

[亡魂溺海] 提交于 2019-12-08 14:01:42
问题 I have a class of computer and each of it can be assembled. I need to retrieve those records of Computer class that has Assembler. I've tried to use criteria but could not retrieve them. @Entity public class Computer{ .... @OneToMany private Set <Assembler> assemblers; .... } @Entity public class Assembler{ ... @OneToOne private User user; @OneToMany @LazyCollection(LazyCollectionOption.FALSE) private Set<Tools> tools; .... } @Entity public class Tools{ .... @OneToOne private Electronic

Hibernate - How to map and relate a class from another Schema?

萝らか妹 提交于 2019-12-08 13:52:05
问题 This question is a bit complicated for me to explain. So I will divide it in parts and try to draw some pictures. Most questions that I've read before posting, especially on stackoverflow does not contemplate a certain subject, which is about relating a Class 'A' from Schema S' to a Class 'B' from Schema X' Current Configuration Mysql Java Hibernate Explanation I have 1 schema (call it S' ) that contains tables which contains information that is accessed by several companies. Those companies

Posting a complete model object to the controller when only few attributes are used in a form

≡放荡痞女 提交于 2019-12-08 12:22:49
问题 I've read somewhere that for spring mvc, it is a expected behavior to get back NULL in case a form does not contain all the attributes of the model object set by the @ModelAttribute annotiation. S how can I use forms that don't have all the fields of the model object and still recieve the whole but updated object back to the post method of the controller. A short example code of my intention: Part of the controller: .... @RequestMapping(value = "/edit/{id}", method = RequestMethod.GET) public

Why am I getting org.hibernate.id.IdentifierGenerationException?

坚强是说给别人听的谎言 提交于 2019-12-08 11:45:08
问题 As I run my main class (Runner) program I get the following exception : org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: country I don't know the reason, why am I getting this exception. The mapping xml : <hibernate-mapping> <class name="pojo.Country" table="country"> <id name="countryID" column="c_id"> <generator class="increment" /> </id> <property name="countryName" column="c_name" /> <one-to-one class="pojo.PM" name="pm" cascade="all" /

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