hibernate-annotations

Hibernate 4 Annotation Configuration

风流意气都作罢 提交于 2019-12-06 00:26:51
问题 I'm trying to use Hibernate 4 with annotations only, and a hibernate.cfg.xml file. I've made my own annotation and am using reflection to add this to the configuration. I'm able to use Hibernate 4 in this manner fine, but my configuration is being built using a deprecated method. final Configuration configuration = new Configuration(); final Reflections reflections = new Reflections(Item.class.getPackage().getName()); final Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity

hibernate not generate auto increment constraint on mysql table

谁说我不能喝 提交于 2019-12-05 20:55:54
I have been searching through different forums for the problem and had tried different solutions but i am still unable to find any correct answer for my problem. I am using hibernate4 annotations for mapping my entities. everything works fine but only auto increment key is not detected when tables are created using hibernate in mysql. i have following code: @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(unique = true, nullable = false) private int responseId; i also have tried @Id @GenericGenerator(name="generator", strategy="increment") @GeneratedValue(generator="generator")

Hibernate JPA IdentifierGenerationException: null id generated for class with @embeddedid

匆匆过客 提交于 2019-12-05 09:32:32
I am having trouble mapping my database domain model to the program entities in one case where the entity is essentially a join table (a period) which combines two other entities (a timeslot and a day). Another entity (a lesson) then has a reference to this period entity, determining when it occurs. When I try to save a lesson with a new period using saveOrUpdate(lesson) hibernate throws an IdentifierGenerationException org.hibernate.id.IdentifierGenerationException: null id generated for:class com.trials.domain.Period The database looks like below (not the real database, just the key tables

JVM crashing when using any other Hibernate inheritance strategy besides SINGLE_TABLE

安稳与你 提交于 2019-12-05 01:26:56
问题 Ok, this is probably a longshot but here goes. In Java (JRE 1.6.0_26-b03) I have two classes, SuperControl and its subclass SubControl . They both need to be persistent objects and I'm using Hibernate Annotations to achieve this. I have approximately 210 classes that are being persisted correctly. Except one isn't. My problem is that SubControl refuses to inherit in any way besides SINGLE_TABLE . When I say "refuses", I mean that the entire JRE crashes . This is a bit problematic because I'd

How to join fields of two tables using Hibernate?

谁都会走 提交于 2019-12-04 14:04:42
I have two tables and related Java mapping. CREATE TABLE country ( code VARCHAR(3) PRIMARY KEY NOT NULL, name VARCHAR(100) NOT NULL ); CREATE TABLE user ( id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, country_code VARCHAR(3), FOREIGN KEY ( country_code ) REFERENCES country ( code ) ); Here is my Java entities. Country POJO: @Entity @Table(name = "country") public class Country { @Id @Column (name = "code") private String code; @Column (name = "name") private String name; And User POJO: @Entity @Table(name = "user") public class User implements Serializable { @Id

hibernate one to many using a join table, and hibernate annotations

僤鯓⒐⒋嵵緔 提交于 2019-12-04 11:11:53
问题 I want do a one-to-many relationship between two tables using a join table. This is why I want to use a join table: Hibernate unidirectional one to many association - why is a join table better? Why is it recommended to avoid unidirectional one-to-many association on a foreign key? Finally, I want to use Hibernate annotations to perform this. I found some examples to do this using xml mapping but nothing with annotations. I believe this would be how the tables need to be created CREATE TABLE

Hibernate Polymorphism.EXPLICIT annotation doesn't work?

泄露秘密 提交于 2019-12-04 08:39:14
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 public class B extends A{ String value; public B(){ } public B(String value) { super(); this.value =

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.

How to create meta annotations on field level?

瘦欲@ 提交于 2019-12-04 05:18:25
I have this hibernate class with annotations: @Entity public class SimponsFamily{ @Id @TableGenerator(name = ENTITY_ID_GENERATOR, table = ENTITY_ID_GENERATOR_TABLE, pkColumnName = ENTITY_ID_GENERATOR_TABLE_PK_COLUMN_NAME, valueColumnName = ENTITY_ID_GENERATOR_TABLE_VALUE_COLUMN_NAME) @GeneratedValue(strategy = GenerationType.TABLE, generator = ENTITY_ID_GENERATOR) private long id; ... } Since I don´t won´t to annotate every id field of my classes that way, I tried to create a custom anotation: @TableGenerator(name = ENTITY_ID_GENERATOR, table = ENTITY_ID_GENERATOR_TABLE, pkColumnName = ENTITY

Hibernate 4 Annotation Configuration

非 Y 不嫁゛ 提交于 2019-12-04 04:23:26
I'm trying to use Hibernate 4 with annotations only, and a hibernate.cfg.xml file. I've made my own annotation and am using reflection to add this to the configuration. I'm able to use Hibernate 4 in this manner fine, but my configuration is being built using a deprecated method. final Configuration configuration = new Configuration(); final Reflections reflections = new Reflections(Item.class.getPackage().getName()); final Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity.class); for (final Class<?> clazz : classes) { configuration.addAnnotatedClass(clazz); } return