hibernate-mapping

org.hibernate.exception.SQLGrammarException: could not insert [com.sample.Person]

[亡魂溺海] 提交于 2019-12-04 13:13:29
问题 I'm trying to set up a small working sample of Hibernate that I found here However when I run the code I get the follwing error Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.sample.Person] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate

How do I configure JPA table name at runtime?

荒凉一梦 提交于 2019-12-04 10:55:19
I have an issue where I have only one database to use but I have multiple servers where I want them to use a different table name for each server. Right now my class is configured as: @Entity @Table(name="loader_queue") class LoaderQueue I want to be able to have dev1 server point to loader_queue_dev1 table, and dev2 server point to loader_queue_dev2 table for instance. Is there a way i can do this with or without using annotations? I want to be able to have one single build and then at runtime use something like a system property to change that table name. For Hibernate 4.x, you can use a

Using an uuid or guid as id in grails/hibernate

一个人想着一个人 提交于 2019-12-04 10:02:00
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 on h2 results in another error - detaling that DB does not support GUIDs, as expected). I get this error

Stripping trailing whitespace from char fields in a legacy database with Grails GORM

℡╲_俬逩灬. 提交于 2019-12-04 07:55:49
What are the possible solutions for stripping the trailing whitespace when mapping char fields in a legacy database? I see the following options: Calling .trim() at the point of use (controller, view, etc) Override property accessors to return .trim() Using a Hibernate UserType to trim the whitespace I'm leaning toward overriding the property accessor so that the domain properties remain consistent throughout the application. I had a similar problem and I could not alter the legacy data. I ended up overriding the accessor for the sake of transparency to my fellow developers. I would recommend

nvarchar in sql ,oracle and mysql in Hibernate annotation mapping

六眼飞鱼酱① 提交于 2019-12-04 05:22:28
问题 We are using MS-SQL ,Oracle and mysql as our database. We have used hibernate annotations to create tables, in the annotation class file we have declared column definition as @Column(name="UCAALSNO",nullable=false,columnDefinition="nvarchar(20)") and this works fine for MS-SQL. But when it comes to Oracle nvarchar throws an exception as oracle supports only nvarchar2 and Mysql only supports nchar()(max length=255) How to create annotation file to support datatype nvarchar for three databases.

Is it possible to have foreign key enforced without object-to-object mapping?

纵然是瞬间 提交于 2019-12-04 03:22:30
问题 Assuming the following mappings are provided: <class name="A" table="a_table"> <id name="id"/> <many-to-one name="entityB" column="fk_B" not-null="false" unique="true"/> </class> <class name="B" table="b_table"> <id name="id"/> </class> Java class: public class A { private long id; private B entityB; // getters and setters skipped } Is it possible to change the Hibernate mapping so that foreign key is still enforced and created by Hibernate upon startup , but class A would look like as the

Adding an enum as a class property in HBM

孤街浪徒 提交于 2019-12-03 19:47:59
问题 I am trying to create a class in HBM file which contains an Enum as a field. The HBM is similar to this: <class name="a.b.c.myObject" table="OBJECT" > <property name="myEnum" column="EXAMPLE" type="a.b.c.myEnum" /> </class> and let's say that this is the Enum: public enum myEnum{ a, b, c; } The problem is that in the DB I expected to see the String value of that enum (a,b or c) but instead I got the raw data of that field. How can I solve that? 回答1: Here is the solution with Hibernate 3.6.x :

Hibernate Validator - Add a Dynamic ConstraintValidator

此生再无相见时 提交于 2019-12-03 14:38:42
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, Serializable>> validator(); } So that I could use @CustomAnnotation in this manner @CustomAnnotation

Hibernate 2nd level cache objects that are lazy=false, result in a default fetch=join, is it documented anywhere?

你说的曾经没有我的故事 提交于 2019-12-03 14:17:12
I experience the following apparently undocumented issue, and I want to understand if I did something wrong Did anyone encounter the same issue? Is it really not documented anywhere? or did I miss something? The behavior is this Assume the following mapping <class name="org.sample.Foo" table="foo"> ... <many-to-one name="bar" class="org.sample.Bar"/> </class> <class name="org.sample.Bar" table="bar" lazy="false"> ... </class> First, as a background, Hibernate default value for the fetch attribute on a many-to-one relation should be " select ", this is at least what is documented (I'll add the

Mapping problem with Hibernate

送分小仙女□ 提交于 2019-12-03 14:03:21
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 structure. any advice would be great. 484 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing