天道酬勤,学无止境

hibernate-mapping

404 Error in Associate Mapping

问题 我正在开发购物车网络应用程序,该应用程序已完成显示产品以添加购物车。 我正在尝试将每个客户(一对一)映射到购物车实体,将购物车实体(一对一)映射到购物车项目实体,并将购物车项目实体(多对一)映射到产品实体。 但是我收到了 404 错误。 请在下面检查我的代码。 测绘计划: 客户-----一对一----->购物车----一对一---->购物车项目----多对一--->产品 客户实体 package com.model; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; import javax.validation.constraints.NotNull; import org

2022-05-16 15:32:19    分类:技术分享    spring   hibernate   spring-mvc   hibernate-mapping

HIbernate Mapping Exception: PropertyNotFoundException: Could not find a setter

问题 我有两个 POJO,STOCK 和 STOCK_DETAILS(一对多关系)。 我也有一个接口 IAUDITLOG(有两种方法)。 我需要用两个 POJO 来实现这个接口,并且想在这些方法中编写一些实现。 但是当我用子类“STOCKDETAILS”实现 IAUDITLOG 接口时,它会给出异常“你应该有 setter 属性” 股票类别: @Entity @Table(name = "stock") public class Stock implements java.io.Serializable, IAuditLog { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id") private Integer stockId; @Column(name = "STOCK_CODE") private String stockCode; @Column(name = "STOCK_NAME") private String stockName; @OneToMany( fetch = FetchType.LAZY, mappedBy = "stock") public Set<StockDetail> stockDetails =

2022-05-07 10:34:04    分类:技术分享    java   spring   hibernate   hibernate-mapping

how to add @onetoone mapping for self entity in hibernate

问题 @Entity @Table(name="PERSON") public class Person { @Id @Column(name="personId") private int id; @OneToOne @JoinColumn() private Person parentPerson; } 回答1 这是双向自映射@OneToOne的示例(我将列名更改为 SQL 表示法): @Entity @Table(name="PERSON") public class Person { @Id @Column(name="person_id") private int id; @OneToOne @JoinColumn(name = "parent_person_id") private Person parentPerson; @OneToOne(mappedBy = "parentPerson") private Person childPerson; } 但是,我不明白你为什么要在这种情况下使用@OneToOne 。 回答2 我这样使用它: @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumn(name = "PARENT_ID", nullable = true)

2022-05-06 09:49:04    分类:技术分享    spring   hibernate   hibernate-mapping   hibernate-annotations

Is it possible to map different field types using hibernate?

问题 我想知道是否可以映射不同的数据类型。 例如,我在 Java 中有一个 Visit 数据类型,它有一个 String 类型的 userEmail 字段,我可以用 hibernate 将它映射到一个具有 userID 而不是 userEmail 的数据库表吗? 根据 id 它会找到电子邮件并将电子邮件返回给 java,反之亦然? 这可能吗? 如果是,那么映射会是什么样子? 或者这应该是什么样子: <many-to-one name="patientEmail" column="idPatient" not-null="true" class="com.my.myapp.datamodel.Patient"/> 回答1 是的你可以。 您必须创建一个扩展为 Hibernate 的 UserType 的类。 自定义用户类型休眠 它可以是像这样的用户: @Column(name = "commission_type") @Type(type = "com.core.commission.model.FNEnumUserType", parameters = @Parameter(name = "type", value = "com.core.commission.dto.CommissionType")) private CommissionType commissionType

2022-05-04 16:21:02    分类:技术分享    java   hibernate   orm   hibernate-mapping

Hibernate "No session or session was closed" when i trying to get data from database

问题 我正在尝试编写一个库存管理系统。 但现在我有几个问题。 请帮我解决这些问题。 我有 2 个实体。 Item和项目ItemPrice 。 Item有一个或多个ItemPrice 当我尝试保存Item对象时,它工作正常; 但是当我尝试从数据库中检索详细信息时,它会给出以下Exception堆栈跟踪。 org.hibernate.HibernateException: Found shared references to a collection: com.pos.entities.ItemGroup.items Hibernate: select itemmodel0_.id as id9_, itemmodel0_.item_model as item2_9_, itemmodel0_.status as status9_ from smartpos.item_model itemmodel0_ where (itemmodel0_.status=? ) Hibernate: select itemsize0_.id as id3_, itemsize0_.item_size as item2_3_, itemsize0_.status as status3_ from smartpos.item_size itemsize0_ where (itemsize0_.status

2022-05-04 12:55:08    分类:技术分享    java   hibernate   hibernate-mapping

Hibernate in AWS Lambdas leads to slow startups

I have some AWS Lambda functions that perform database CRUD operations. I have about 20 persistent classes. My application is Spring-based and uses Hibernate for the ORM. With 1536MB allocated, my function takes about 16 seconds to run from cold start. According to the logs, most of this time is Hibernate parsing my hbm.xml files, building LoadPlans, and generally processing metadata. Since a response time of 16 seconds is far too much, I need ways to speed this up. Is there a way to defer Hibernate's metadata parsing or to do it at compile time? I've taken a look at the JPA metamodel

2022-05-02 17:35:25    分类:问答    java   hibernate   aws-lambda   hibernate-mapping

how to add @onetoone mapping for self entity in hibernate

how to add one-to-one mapping for the self entity. Like in this example. I want to have parent-child relationship for the Person itself. @Entity @Table(name="PERSON") public class Person { @Id @Column(name="personId") private int id; @OneToOne @JoinColumn() private Person parentPerson; }

2022-05-02 02:35:30    分类:问答    spring   hibernate   hibernate-mapping   hibernate-annotations

Why does Hibernate 5 sequence generator use the default hibernate.seq instead of my sequence?

问题 在将我的应用程序从休眠 4 迁移到休眠 5 之后。我的序列不起作用,休眠使用我们的默认序列而不是我的序列。我在 hbm 中的映射配置就像这样我的数据库是 oracle。 <id name="id" column="Id" type="java.lang.Long"> <generator class="sequence" > <param name="sequence">SEQ_APP_Login_Log</param> </generator> </id> 在谷歌之后,有人说将类更改为 org.hibernate.id.enhanced.SequenceStyleGenerator 但不再起作用。 回答1 <id name="id" column="Id" type="java.lang.Long"> <generator class="sequence" > <param name="sequence_name">SEQ_APP_Login_Log</param> </generator> </id>

2022-04-30 06:09:31    分类:技术分享    java   hibernate   orm   hibernate-mapping   hibernate-5.x

Hibernate "No session or session was closed" when i trying to get data from database

I am trying to write a stock management system. But now I have a few question. Please help me to sort out these problems. I have 2 entities. Item and ItemPrice. Item has one or more ItemPrice When I try to save Item object, it works fine; but when I try to retrieve details from database, it gives following Exception stack trace. org.hibernate.HibernateException: Found shared references to a collection: com.pos.entities.ItemGroup.items Hibernate: select itemmodel0_.id as id9_, itemmodel0_.item_model as item2_9_, itemmodel0_.status as status9_ from smartpos.item_model itemmodel0_ where

2022-04-30 05:43:41    分类:问答    java   hibernate   hibernate-mapping

HIbernate Mapping Exception: PropertyNotFoundException: Could not find a setter

I have two POJO's ,STOCK and STOCK_DETAILS (one to many relationship). Also I have one interface IAUDITLOG (having two methods). I need to implement this interface with BOTH POJO's and want to write some implementation within those methods. But when I implement IAUDITLOG interface with child class "STOCKDETAILS" then it gives exception "that you should have setter property" STOCK CLASS: @Entity @Table(name = "stock") public class Stock implements java.io.Serializable, IAuditLog { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id") private

2022-04-29 17:08:32    分类:问答    java   spring   hibernate   hibernate-mapping