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" />
...
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 ...
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...
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...
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...
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...
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?
...
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...
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...
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 ...
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?
...
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...
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...
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...
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 ...
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;
...
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...
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
-------------------------...
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...
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...