Tag: hibernate annotations

mappedBy引用一个未知的目标实体属性

我有一个问题,在我的注释对象中build立一对多的关系。 我有以下几点: @MappedSuperclass public abstract class MappedModel { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id",nullable=false,unique=true) private Long mId; 那么这个 @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<Store> stores; 和这个 @Entity […]

@UniqueConstraint和@Column(unique = true)在hibernate注释中

@UniqueConstraint和@Column(unique = true)有什么区别? 例如: @Table( name = "product_serial_group_mask", uniqueConstraints = {@UniqueConstraint(columnNames = {"mask", "group"})} ) 和 @Column(unique = true) @ManyToOne(optional = false, fetch = FetchType.EAGER) private ProductSerialMask mask; @Column(unique = true) @ManyToOne(optional = false, fetch = FetchType.EAGER) private Group group;

我如何创build一个使用hibernate注释的外键约束?

我正在尝试使用hibernate注释为我的数据库表编写模型类。 我有两个表,每个都有一个主键用户和问题。 @Entity @Table(name="USER") public class User { @Id @Column(name="user_id") @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @Column(name="username") private String username; // getter and setter } 问题表。 @Entity @Table(name="QUESTION") public class Questions extends BaseEntity{ @Id @Column(name="question_id") @GeneratedValue(strategy=GenerationType.AUTO) private int id; @Column(name="question_text") private String question_text; // getter and setter } 而且我还有一个表UserAnswer,它具有userId和questionId作为上述两个表中的外键。 但我无法find如何在UserAnswer表中引用这些约束。 @Entity @Table(name="UserAnswer ") public class UserAnswer { […]

hibernateexception:org.hibernate.AnnotationException:没有为实体指定标识符:com..domain.idea.MAE_MFEView

为什么我得到这个exception? package com.domain.idea; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; import org.hibernate.annotations.AccessType; /** * object model for the view [InvestmentReturn].[vMAE_MFE] */ @Entity @Table(name="vMAE_MFE", schema="InvestmentReturn") @AccessType("field") public class MAE_MFEView { /** * trade property is a SuggestdTradeRecommendation object */ @OneToOne(fetch = FetchType.LAZY , cascade = { CascadeType.PERSIST }) @JoinColumn(name = "suggestedTradeRecommendationID") […]

Hibernate映射包

我正在使用Hibernate注释。 在我所有的模型类中,我都是这样注解的: @Entity @Table public class SomeModelClass { // } 我的hibernate.cfg.xml是 <hibernate-configuration> <session-factory> <!– some properties –> <mapping package="com.fooPackage" /> <mapping class="com.fooPackage.SomeModelClass" /> </session-factory> </hibernate-configuration> 对于添加到com.fooPackage中的每个类,我都必须在hibernate.cfg.xml中添加一行,如下所示: <mapping class="com.fooPackage.AnotherModelClass" /> 有没有办法可以添加新的模型类,但不需要将此行添加到hibernate.cfg.xml?

混乱:@NotNull vs @Column(nullable = false)

当他们出现在@Entity的字段/ getter时,他们之间有什么区别? (我坚持实体通过hibernate )。 他们每个人所属的框架和/或规格是什么? @NotNull位于javax.validation.constraints 。 在javax.validation.constraints.NotNull javadoc中说 注释元素不能为空 但是它并不涉及数据库中元素的表示,所以为什么要将约束nullable=false添加到列?