hibernate-mapping

access data from two table

谁说我不能喝 提交于 2020-01-05 08:21:32
问题 Customer class have name property that corresponds to name field in customer table. Customer class also define the map that use for put the fieldName and fieldValue. on database customer name define in customer table and fieldvalue define in form table. now how i can retrieve customer name from customer table and fieldvalue from form table. in hbm file: <map name="formFields" table="form" cascade="all-delete-orphan" lazy="true"> <key column="id"/> <index column="fieldName" type="string"/>

Hibernate reverse engineering - mapping a table to Java enum

落爺英雄遲暮 提交于 2020-01-04 09:07:30
问题 I'm working on a project where I am using JBoss Tools to reverse engineer an MS SqlServer database into Hibernate objects. I am wondering if there is a way to map some of the tables in my schema to Java enums? Can this be configured in the hibernate.reveng.xml file? If so, do you have an example? Thanks! 回答1: This open issue indicates that enums are not supported by hibernate reveng. 来源: https://stackoverflow.com/questions/7679044/hibernate-reverse-engineering-mapping-a-table-to-java-enum

Is it possible to force Hibernate to embed an Entity?

瘦欲@ 提交于 2020-01-04 05:14:25
问题 In my use-case, I would like to @Embedded a class C in an entity. Another entity refers to C with @OneToMany association and therefore C is annotated with @Entity . I am aware that this seems like bad design, yet I believe that it makes perfect sense in my case. Is it possible to force Hibernate to embed an Entity? If I try it, Hibernate complains about a missing setter for the id property of C. I think the problem comes from this: @Id @GeneratedValue(strategy = GenerationType.TABLE) private

ERROR: ORA-02289: sequence does not exist - org.hibernate.exception.SQLGrammarException: could not extract ResultSet

社会主义新天地 提交于 2020-01-03 08:21:48
问题 I am creating a basic hibernate application for employee table in which I am adding, updating, deleting and displaying the record with the help of ManageEmployee class. Actually, ManageEmployee is my test class and i am using Employee.java and Employee.hbm.xml file to do above things. Details: Database: Oracle 11 g Hibernate version: hibernate-release-4.3.8.Final Java Version: Java 1.8 Employee Table Details: USER_ID NUMBER(15,0) No 1 1 FIRST_NAME VARCHAR2(20 BYTE) Yes 2 LAST_NAME VARCHAR2(20

One to many cascade All is not setting parent id while child entry insertion

家住魔仙堡 提交于 2020-01-03 03:02:07
问题 I am using Hibernate 3 annotations. I have a table 'product' and child table 'product_spec' with one-to-many relation. When i do hibernateTemplate.save(product) it is giving error could not insert: [com.xx.ProductSpec]; SQL [insert into Products_spec Column 'PRODUCT_ID' cannot be null @Entity @Table(name = "product") public class Product implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue @Column(name = "PRODUCT_ID") private Integer productId;

Hibernate:Difference between setting the Id directly in the bean or calling the load() or get() method?

纵然是瞬间 提交于 2020-01-02 16:29:53
问题 Following is an example of load:- Stock stock = (Stock)session.load(Stock.class, new Integer(2)); StockTransaction stockTransactions = new StockTransaction(); //set stockTransactions detail stockTransactions.setStock(stock); session.save(stockTransactions); What is the difference if i directely set the id in like:- Stock stock =new Stock(); stock.setId(2); StockTransaction stockTransactions = new StockTransaction(); //set stockTransactions detail stockTransactions.setStock(stock); session

java.lang.NullPointerException at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:521)

☆樱花仙子☆ 提交于 2020-01-02 15:02:30
问题 I am new to hibernate, I just had some doubts and clarified in this website (One to many relationship and Other object relation). For the same application i am facing different issue. the exception is, what i am missing in this app. Hibernate: insert into TestDB.customer (name, registrationDate) values (?, ?) Hibernate: insert into TestDB.tickets (accessories, comments, uid, problem, problemFiledDate, repairTye, status, statusChangedDate) values (?, ?, ?, ?, ?, ?, ?, ?) Exception in thread

Hibernate auto-increment property

拈花ヽ惹草 提交于 2020-01-02 05:08:42
问题 I know you can auto-increment an id by mapping; <id column="user_id" name="id" > <generator class="increment"/> </id> But is it also possible increment a property, what I tried so far didn't work; <property column="numeric_value" name="nr" > <generator class="increment"/> </property> 回答1: But is it also possible increment a property, what I tried so far didn't work; No, you can't use a <generator> inside a <property> (or, to write it in plain english, Hibernate only supports using a generator

Set creation and update time with Hibernate in Xml mappings

淺唱寂寞╮ 提交于 2020-01-02 04:23:09
问题 I'm using Hibernate with Xml mappings. I have an entity that has two fields creationDate and updateDate of type timestamp , that have to be filled with the current UTC time when the entity is persisted and updated. I know about the existence of the @PrePersist and @PreUpdate annotations, but i don't know how to use their equivalent in my Xml mappings. Again, i was wondering if Hibernate somehow supports natively the update and creation time set. Thanks 回答1: I know about the existence of the

Using an uuid or guid as id in grails/hibernate

不问归期 提交于 2020-01-01 11:45:13
问题 I need to have GUID/UUID's as the id column of my rows. This is to be able to create entries both online and offline, and of course not having these conflict on PK when merging. I know i could mitigate this, but i'd like to keep it simple, and there is legacy apps already using uuid/guids to define relationships). Data also needs to be synced both ways later. Rewriting existing applications is not an option. When i try to use either GUID or UUID with grails i get an error 500. (using a GUID