嗨,StackOverflow社区,
我在HQL查询方面有问题。对于金融应用程序,我们希望获得基于给定的TradeTicket实体的StrategyInstrument实体。以下是定义的实体(省略了详细信息,只显示了关系)。
@Entity
public class Trade {
@ManyToOne
private Ticket ticket;
@ManyToOne
private Order buyOrder;
@ManyToOne
private Order sellOrder;
...
}
@Entity
public
在JPA/Hibernate中,可以在不添加关系的情况下表示外键吗?
在聚合根中的DDD中,我希望拥有其他聚合根的id --我不希望有对这个聚合的引用,只有id。是否可以通过hibernate强制执行外键?(我使用hibernate自动模式生成)。
例如
@Entity
Person {
...
}
@Entity
Event {
@Id
private long eventId;
@ForeignKey(references Person.id)
private long personId;
// I don't w
当我使用hibernate在表中插入记录时,它会给出像-这样的异常:
org.hibernate.HibernateException: The database returned no natively generated identity value
at org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity(IdentifierGeneratorHelper.java:90)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.execute
错误: org.hibernate.QueryException:无法解析属性: codigo
代码如下:
System.out.println("Codigo del curso que quiere consultar las matriculas");
codigo = intSc.nextInt();
Cursos curso = (Cursos) session.get(Matricula.class, codigo);
Query query1 = session.createQuery("SELECT m FROM Matricula m where m.
我有以下课程(简化):
位置
表示地理区域
@Entity
@Table(name = "location")
public class Location extends DomainObject {
@OneToMany(mappedBy = "lastPositionHistoric.location")
private Set<Thing> things = new LinkedHashSet<>(0);
public Location() {
}
public Set<Thing
当我调用configuration.configure(hibernate.cfg.xml).buildSessionFactory()时,我得到了以下异常
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.Logger.isTraceEnabled()Z
at org.hibernate.type.NullableType.<clinit>(NullableType.java:59)
at org.hibernate.Hibernate.<clinit>(
我有一个OneToMany从电影到他们所有的语言版本实体,我也想有一个manyToOne的原始版本。此版本包含一个布尔型orginal = true,以将版本限制为唯一具有原始= true属性的版本。因此,我尝试使用Forumla来限制版本:@Join式(value=“”(从persistence.model.Version v中选择v.film.id = id和v.original为true ),但是在生成film0_时,hibernate前缀为film0_,因此不起作用(在SQL中得到fiml0_.true)。
@Entity
public class Film implements Se
我有一张名叫乡村、城市和人的桌子。如何防止hibernate来保存相同的人员对象?下面是我的类,问题是当我试图保存一个国家对象时,Hibernate试图按预期保存或更新相同的人员对象(城市的people对象和country的people对象有相同的PK)
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session
课程;
class Country{
.....
@JoinColumn(...
为简单起见,下面是示例数据模型。
USER STATUS
======== >|------------|- ======
id status
username
password
status
在hibernate中有不同的建模验证表的方法吗?此外,一个表可以有多个验证表。
我想在Hibernate侧为状态实体创建枚举,该实体具有从数据库填充的数据。从用户实体中,我可以引用状态实体枚举来访问值。如果可能,避免在用户实体上建立ManyToOne关系。
我试图查看hibernate文档,但在那
假设我有Hibernate实体类A,B,C。B是A和C的字段。现在,我想根据C的其他字段的条件来检索A。我该怎么做呢?
@Entity
@Table(name = "A")
@Proxy(lazy = false)
public class A {
...
@ManyToOne
@JoinColumn(name = "b_ID")
private B b;
...
}
@Entity
@Table(name = "C")
@Proxy(lazy = false)
public class C
AssignCoScholastic.java
@Entity
@Table(name="assignCoScholastic")
public class AssignCoScholastic
{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int assginCoScholasticId;
@ManyToOne
@JoinColumn(name="assignClassId")
我遇到了一个类故障,它应该表示mysql数据库中的一个表,但是由于某种原因不能创建该表。在我添加类之前,它运行得非常完美,但是现在我得到了以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguratio
我试图使用Hibernate事件侦听器(如: PostInsertEventListener、PostUpdateEventListener和PostDeleteEventListener )编写审计日志。但是,当使用entityManager将数据从持久性上下文中刷新到以下侦听器中的数据库时,我遇到了问题:
以下是源代码:
EntityA.class
@Entity
@Table(name = "ENTITY_A")
public class EntityA implements Serializable {
private static final long seria
我有一个问题,当我运行hibernate时,它显示了"Caused by: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: com.trein.Moneda.documento"的错误,而事实是我不知道它为什么要抛出这个错误。它似乎在Moneda.java类中失败了
Documento.java
@ManyToOne
@JoinColumn(name = "pa
我的问题是我得到了LazyInitializationException。
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:148) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.proxy.AbstractLazyInit
我想要创建一个表,其中对象的primary key也应该作为两个@ManyToOne表的foreign key。
如果不创建额外的表列,同时引用和重复相同的主键id,这是可能的吗?
示例:
@Entity
public class Person {
@Id
private int personId;
@ManyToOne
@JoinColumn(name="fk_address_id", foreignKey=@ForeignKey(name="fk_address"))
private Address address;
我正在试验spring和jpa的ManyToOne in 。实体之间的关系是,一个Cart (购物车)可以有多个Item(跟随)。
Cart
@Entity
@Table(name="CART")
public class Cart
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cart_id")
private long id;
@OneToMany(mappedBy = "cart")
p