hibernate-annotations

Hibernate Mapping Package

I'm using Hibernate Annotations. In all my model classes I annotate like this: @Entity @Table public class SomeModelClass { // } My hibernate.cfg.xml is <hibernate-configuration> <session-factory> <!-- some properties --> <mapping package="com.fooPackage" /> <mapping class="com.fooPackage.SomeModelClass" /> ...

Wrong SQL for view object using Hibernate Annotations

I'm working on a hibernate entity mapping for a database view; when I do a criteria query against it, hibernate is generating bad SQL. Any help figuring out what the problem is with my mapping would be greatly appreciated! I have two mapped entities which I am trying to grab from a database view; the view has no other columns, just the ...

Hibernate many-to-many association with the same entity

Another Hibernate question... :P Using Hibernate's Annotations framework, I have a User entity. Each User can have a collection of friends: a Collection of other Users. However, I have not been able to figure out how to create a Many-to-Many association within the User class consisting of a list of Users (using a user-friends intermedia...

hibernate @DiscriminatorValue does not apply to associations

I have the following inheritance hierarchy. @Entity @Table(FRUIT) @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColum(name="FRUIT_TYPE",discriminatorType=STRING) public class Fruit { .. @Id private FruitId id; ... } @DiscriminatorValue("APPLE") public class Apple extends Fruit { ... @ManyToOne private FruitBowl bowl...

Hibernate - moving annotations from property (method) level to field level

How do I generate hibernate domain classes from tables with annotations at field level? I used Hibernate Tools project and generated domain classes from the tables in the database. The generated classes have annotations on the getter methods rather than at the field level. Kindly advice a way to generate domain classes that have the fiel...

Hibernate cascade delete not working when removing element of recreated bean

Supposing these are my parent and my child objects: Parent: @Entity @Table( name = "import_table" ) public class ImportTable { @Cascade( { CascadeType.ALL, CascadeType.DELETE_ORPHAN } ) @OneToMany( mappedBy = "table", fetch = FetchType.EAGER ) public List<ImportTableColumn> getColumns() { re...

Persisting large files with Hibernate Annotations

I am using Hibernate Annotations for the first time in my web application. In my bean, what type what annotations should I use to persist files uploaded by users? ...

Issue persisting long strings with Hibernate

In my web application, I have a text area whose user-filled contents are ultimately persisted to the db with Hibernate. I have been running into an issue that when the user input is beyond a certain length, the persistence fails. Is there a way to indicate through Hibernate Annotations or in the configuration that this particular field...

Can a @OneToOne relationship contain a @ForiegnKey annotation

Does it make sense to have a @OneToOne member contain a @ForiegnKey annotation. @Entity class User { @Id @GeneratedValue(strategy = IDENTITY) int id; @OneToOne @ForeignKey @JoinColumn(name = "home_address_id", referencedColumnName = "id") Address homeAddress; } @Entity class Address { @Id @Generat...

hibernate composite Primary key contains a composite foreign key, how to map this..

Hi all, I searched there, and didn't find any similar topic, so I am posting a new question. I am working with Hibernate on an existing Database. The table structure and data we are not allowed to change. The application is reading data from the database and migrating to another datastore based on some logic. Now the problem is about ...

Is it possible to create indices on join table using Hibernate annotations and hbm2ddl?

I have a two entities in many-to-many association. Hibernate creates a join table for this association if hbm2ddl is activated. However, since I do not have an entity for this table, I can not apply @Index annotation. Is there a way to tell hibernate hbm2ddl to generate indices and primary key on the join table? ...

Hibernate Annotation + AspectJ -> Attributes names pbs in HQL

I'm looking for a way to use aspects to inject parameters in hibernate annotated classes. Here is a user : @Entity public class User implements IHasCity { @Id private int id; private String name; } public interface IHasCity { } Here is an aspect contributing to that User public aspect ACity { @Column private S...

JPA/Hibernate DDL generation; CHAR vs. VARCHAR

I have a JPA/Hibernate data model that I am using the Hibernate hbm2ddl tool to generate database DDL. I have some strings that should be CHAR and some that may be VARCHAR in the database. I want to minimize hand editing of the DDL (I realize that some will have to happen). Anyone know how I should go about this? I realize that I can ma...

How to validate database schema programmatically in hibernate with annotations?

It seems that org.hibernate.cfg.Configuration object can be used to perform validation programmatically, by calling the validateSchema method. However, this method needs dialect and databaseMetadata objects. I am using Spring and I can get a hold of AnnotationSessionFactoryBean object from spring context. So far I have the following co...

Hibernate Annotation for Entity existing in more than 1 catalog

I have a Person entity mapped by Hibernate to a database table in a database catalog "Active". After a period of time, records in this database table in the "Active" catalog are archived/moved to an exact copy of the table in a database Catalog "History". I have the need to retrieve from both the Active and History Catalogs. Is there ...

Hibernate mapping - "Could not determine type"

I currently have the following objects persisting successfully: Person first name, etc. Exams title, date, etc. I'd like to now create a third table Exam results. For this table I believe it should be person ID, exam ID and result, and this is a many to many relationship. @Entity public class ExamResult { private Exam exam; ...

Variable length Blob in hibernate?

I have a byte[] member in one of my persistable classes. Normally, I'd just annotate it with @Lob and @Column(name="foo", size=). In this particular case, however, the length of the byte[] can vary a lot (from ~10KB all the way up to ~100MB). If I annotate the column with a size of 128MB, I feel like I'll be wasting a lot of space for t...

Joining tables with composite keys in a legacy system in hibernate

Hi, I'm currently trying to create a pair of Hibernate annotated classes to load (read only) from a pair of tables in a legacy system. The legacy system uses a consistent (if somewhat dated) approach to keying tables. The tables I'm attempting to map are as follows: Customer CustomerAddress -------------------------...

Problem with 2 levels of inheritance in hibernate mapping

Here's my class structure: class A class B extends A class C extends A class D extends C class E extends C And here are my mappings (class bodies omitted for brevity): Class A: @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @MappedSuperclass @DiscriminatorColumn( name="className", discriminatorType=Discr...

Hibernate annotated many-to-one not adding child to parent Collection

I have the following annotated Hibernate entity classes: @Entity public class Cat { @Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO) @Id private Long id; @OneToMany(mappedBy = "cat", cascade = CascadeType.ALL, fetch = FetchType.EAGER) private Set<Kitten> kittens = new HashSet<Kitten>(); public v...