hibernate-mapping

How to configure multiple schemas with Hibernate

早过忘川 提交于 2021-02-19 06:43:46
问题 We have got a requirement for multiple schemas in Hibernate. In our project, we need to connect to multiple schemas based on the username and password. But how to configure multiple schemas in Hibernate? Please let me know if there's a way. 回答1: Thanks to Hibernate Multitenancy support, you can easily do that as follows: The following examples can be found in the Hibernate ORM documentation folder. Each schema can be a tenant, so you only need to provide a tenant identifier to the Hibernate

How do you retrieve nested Sets?

瘦欲@ 提交于 2021-02-17 22:08:56
问题 Is there an annotation I'm missing or is this a limitation to hibernate retrieval? Entities: class A { Long id; Set<B> b; @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "A_B", joinColumns = @JoinColumn(name = "A_ID"), inverseJoinColumns = @JoinColumn(name = "B_ID") public Set<B> getBs() { return b; } } class B { Long id; Set<C> c; @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "B_C", joinColumns = @JoinColumn(name = "B_ID"), inverseJoinColumns = @JoinColumn(name = "C_ID")

How do you retrieve nested Sets?

蓝咒 提交于 2021-02-17 22:08:08
问题 Is there an annotation I'm missing or is this a limitation to hibernate retrieval? Entities: class A { Long id; Set<B> b; @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "A_B", joinColumns = @JoinColumn(name = "A_ID"), inverseJoinColumns = @JoinColumn(name = "B_ID") public Set<B> getBs() { return b; } } class B { Long id; Set<C> c; @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "B_C", joinColumns = @JoinColumn(name = "B_ID"), inverseJoinColumns = @JoinColumn(name = "C_ID")

hibernate and mappedBy: Is it possible to automatically set foreign key without setting bidirectional relationship among objects?

我只是一个虾纸丫 提交于 2021-02-17 03:47:29
问题 Welcome, I have 2 classes: Conversation and Question. One Conversation have many questions. Conversation.java: package com.jcg.jpa.mappedBy; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax

Hibernate @Version annotation

[亡魂溺海] 提交于 2021-02-16 18:12:08
问题 What is the relation between hibernate @version and ManyToOne Mapping. Assume that i am having two tables Department and Employee. Here is Deparment is the master table and Employee in the detail table. In the Employee table, departmentID is reference as foreign key. Here is my classes Public class Department { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long ID; @Version private Long version; //Getters and Setters } public class Employee { @Id @GeneratedValue(strategy =

Hibernate 4.2.20 Object HashCode Method Causing NullPointerException

筅森魡賤 提交于 2021-02-10 03:31:13
问题 I was using Hibernate 4.2.3.FINAL without any issues. When I attempted to upgrade to the latest version 4.2.20.FINAL, I received a NullPointerException when trying to execute a query that loads a list of items. From the stacktrace at the bottom, you can see that my class fails on the hashCode method: com.ovationtix.dao.model.BundledPackageTicket.hashCode(BundledPackageTicket.java:89) This hashCode method looks like this: @Override public int hashCode() { HashCodeBuilder hcb = new

Hibernate 4.2.20 Object HashCode Method Causing NullPointerException

时光毁灭记忆、已成空白 提交于 2021-02-10 03:30:21
问题 I was using Hibernate 4.2.3.FINAL without any issues. When I attempted to upgrade to the latest version 4.2.20.FINAL, I received a NullPointerException when trying to execute a query that loads a list of items. From the stacktrace at the bottom, you can see that my class fails on the hashCode method: com.ovationtix.dao.model.BundledPackageTicket.hashCode(BundledPackageTicket.java:89) This hashCode method looks like this: @Override public int hashCode() { HashCodeBuilder hcb = new

Transactional annotation doesn't solve org.hibernate.LazyInitializationException

北战南征 提交于 2021-01-29 06:20:04
问题 I'm writing a simple Spring Data JPA application. I use MySQL database. There are two simple tables: Department Employee Each employee works in some department (Employee.department_id). I have two entity classes: @Entity public class Department { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id private Long id; @Basic(fetch = FetchType.LAZY) @OneToMany(mappedBy = "department") List<Employee> employees; } @Entity public class Person { @GeneratedValue(strategy = GenerationType.IDENTITY)

Hibernate caching not working for inverse side of one-to-one relationship

社会主义新天地 提交于 2021-01-28 07:00:41
问题 I tried googling this and found a possible duplicate of the question, but I cannot preview it: https://stackoverflow.com/questions/49344593/inverse-side-one-to-one-relationship-caching-not-working Given two domain model classess: @Entity @Table(name = "object_a") @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public class ObjectA extends AbstractEntity { private String name; @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "object_b_id") private ObjectB

Unidirectional @OnetoMany mapping deletes all relationships and re-adds remaining ones rather than removing the specific one

╄→尐↘猪︶ㄣ 提交于 2021-01-28 01:56:22
问题 Given the following code public class Course { @Id @GeneratedValue private Long id; private String name; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) private List<Review> reviews = new ArrayList<>(); } public class Review { @Id @GeneratedValue private Long id; @Column(nullable = false) private String rating; private String description; } Saved course with 2 reviews. If I try to remove one review from course. course.getReviews().remove(0); Hibernate fires following queries.