hibernate-annotations

mappedBy reference an unknown target entity property

[亡魂溺海] 提交于 2019-11-27 11:32:02
I am having an issue in setting up a one to many relationship in my annotated object. I have the following: @MappedSuperclass public abstract class MappedModel { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id",nullable=false,unique=true) private Long mId; then this @Entity @Table(name="customer") public class Customer extends MappedModel implements Serializable { /** * */ private static final long serialVersionUID = -2543425088717298236L; /** The collection of stores. */ @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.LAZY) private Collection

Java: Hibernate @OneToOne mapping

ぐ巨炮叔叔 提交于 2019-11-27 07:07:05
I'm trying to get Hibernate @OneToOne annotations working and not having much success here... Let's say I've got a table called status that looks like this: +------------------------------------------------+ | status | +------------------------------------------------+ | id | frn_user_id | frn_content_id | status | +----+-------------+----------------+------------+ | 1 | 111 | 0 | "active" | +----+-------------+----------------+------------+ | 2 | 0 | 222 | "inactive" | +----+-------------+----------------+------------+ And I've got an entity for User that looks like this: @Entity @Table(name

Hibernate recursive many-to-many association with the same entity

一个人想着一个人 提交于 2019-11-27 06:23:07
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 User s. 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 User s (using a user-friends intermediate table). Here's the User class and its annotations: @Entity @Table(name="tbl_users") public class User { @Id @GeneratedValue @Column(name="uid") private Integer uid; ... @ManyToMany( cascade={CascadeType.PERSIST, CascadeType.MERGE}, targetEntity=org.beans

can someone please explain me @MapsId in hibernate?

﹥>﹥吖頭↗ 提交于 2019-11-27 04:20:14
Can someone please explain me @MapsId in hibernate ? I'm having a hard time understanding it. It would be great if one could explain it with an example and in what kind of use cases is it most applicable ? Here is a nice explanation from Object DB . Designates a ManyToOne or OneToOne relationship attribute that provides the mapping for an EmbeddedId primary key, an attribute within an EmbeddedId primary key, or a simple primary key of the parent entity. The value element specifies the attribute within a composite key to which the relationship attribute corresponds. If the entity's primary key

Hibernate recursive many-to-many association with the same entity

自闭症网瘾萝莉.ら 提交于 2019-11-27 03:57:28
问题 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 User s. 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 User s (using a user-friends intermediate table). Here's the User class and its annotations: @Entity @Table(name="tbl_users") public class User { @Id @GeneratedValue @Column(name="uid") private

The annotation @Index is disallowed for this location

痞子三分冷 提交于 2019-11-27 03:04:09
问题 When trying to use the @Index annotation from javax.persistence , Eclipse gives me this error. I'm using it right before a java.util.Date field, inside a class annotated with @Entity . Before, I was using org.hibernate.annotations.Index in the exact same place and it was fine. The problem started after I've upgraded hibernate-core from 4.1.9.Final to 4.3.0.Beta3 and hibernate-commons-annotation s from 4.0.1 to 4.0.2 . It says @Index is deprecated and recommends the javax.persistence one. All

How to enable hibernate filter for sessionFactory.getCurrentSession()?

喜欢而已 提交于 2019-11-27 00:58:50
问题 Say there is a User table with structure: User List item userId (PK) company (PK) userName address ...etc And I want to retrieve users only for the current company (company can be changed by the user through UI, so the company is a runtime parameter) Similarly there are many other tables that have similar structure with common column (company), and I want to restrict data to only the current company, so I am using hibernate filter to filter out data. Hibernate annotations: <bean id=

Hibernate/persistence without @Id

徘徊边缘 提交于 2019-11-26 22:21:48
I have a database view that yields a result set that has no true primary key. I want to use Hibernate/Persistence to map this result set onto Java objects. Of course, because there is no PK, I cannot decorate any field with @Id . When deploying, Hibernate complains about the missing @Id . How can I work around this? If there's a combination of columns that makes a row unique, model a primary key class around the combination of columns. If there isn't, you're basically out of luck -- but you should reexamine the design of the view since it probably doesn't make sense. There are a couple

Hibernate Mapping Package

為{幸葍}努か 提交于 2019-11-26 22:07:56
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" /> </session-factory> </hibernate-configuration> For every class I add to the com.fooPackage I have to add a line in the hibernate.cfg.xml like this: <mapping class="com.fooPackage.AnotherModelClass" /> Is there a way I can add new model classes but don't need to add this line to hibernate.cfg

Looking for a not-deprecated session-factory

元气小坏坏 提交于 2019-11-26 21:40:02
问题 I am dealing with hibernate and as I opened my current project I figured out my Session-Factory is deprecated: AnnotationConfiguration af = new AnnotationConfiguration(); SessionFactory factory = af.configure().buildSessionFactory(); Session session = factory.openSession(); AnnotationConfiguration seems to be deprecated by now... So I checked the JavaDoc and I got told it moved to: org.hibernate.cfg.Configuration My code works fine so far, actually I don't want to change it... But I googled