hibernate-annotations

Hibernate OneToOne relationship

被刻印的时光 ゝ 提交于 2019-12-11 18:34:30
问题 I have two persistence entity: User and UserDetail . They have one-to-one relationship. I use hibernate annotations. But I am getting in my database several objects of user information for one same user. Apparently my knowledge of Hibernate annotations are not so good to solve this problem. User class: @Entity @Table(name = "USER") public class User { @Id @GeneratedValue @Column(name = "ID") private Long id; @Column(name = "NAME") private String name; @Column(name = "PASSWORD") private String

Mapping a class that consists only of a composite PK without @IdClass or @EmbeddedId

断了今生、忘了曾经 提交于 2019-12-11 11:03:40
问题 I've got two tables A and B with simple PK's. @Entity public class A { @Id public int idA; } @Entity public class B { @Id public int idB; } I want to map a new association class AB that simply stores the relations between A and B , with composite PK idA + idB . AB doesn't have any extra columns, just the relation between idA and idB . Is it possible to map AB using a single class? I want to avoid having to create a new ABId class just to use it as @IdClass or @EmbeddedId in AB , and I don't

Mapping issue on Hibernate annotation

微笑、不失礼 提交于 2019-12-11 07:37:40
问题 I have the above tables i need to write the HIbernate entity class with annotation and mapping i have a problem while getting the List of ObjectAttributes.. Class are written as below @Entity public class Object { @Id private int id; private String name; @OneToMany(mappedBy="object",fetch=FetchType.LAZY) private List<ObjectAttribute> attrubuteList; } @Entity public class ObjectAttribute { @Id private int id; @ManyToOne @JoinColumn(name="objectId") private Object object; private String name; }

How to mapping the relations between classes (@ManyToMany) for a table

邮差的信 提交于 2019-12-11 07:08:25
问题 How to mapping the relations between three class @ManyToMany unidirectional for a unique table ? The relations is like that: Project have many Task Many Task have many specifcs Activitys (to standard) - for each task have many specifcs activitys Task and Activitys are standard into the data base. So, when I'll create a Project, I'll chose somes Tasks and somes Task's Activitys. I would to create a table (project_task_activity_map) like that: project_id task_id activity_id 1 2 3 1 2 4 2 1 2 2

ERROR: Unknown column 'this_.idHardDrives' in 'field list'

耗尽温柔 提交于 2019-12-10 21:39:52
问题 Please help with ERROR: Unknown column 'this_.idHardDrives' in 'field list'. Can`t understand the field 'idHardDrives' exist in the database. HardDrives.java package main.java.table; import javax.persistence.*; @Entity @Table(name = "hardDrives") public class HardDrives { @Id @GeneratedValue @Column(name = "idHardDrives") private int idHardDrives; @Column(name = "name") private String nameHardDrives; @Column(name = "capacity") private int capacity; @Column(name = "interface") private String

JPA/Hibernate tries to store too many parameters in entity with composite Id (and doubling properties)

痞子三分冷 提交于 2019-12-10 16:12:56
问题 I have entity with composite Id @Entity @IdClass(value = BorrowId.class) @Table(name = "BORROW") public class Borrow { @Id @Column(name = "BOOK_ID", insertable = false, updatable = false) private long bookId; @Id @Column(name = "BORROWER_ID", insertable = false, updatable = false) private long borrowerId; @Id @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}) @JoinColumn(name = "BOOK_ID") private Book book; @Id @ManyToOne(fetch =

How do I get Hibernate to call my custom typedef?

这一生的挚爱 提交于 2019-12-10 13:11:48
问题 I'm trying to define a CompositeUserType to handle a specific type in my JPA/Hibernate app. I have a CompositeUserType called ApplicationMessageType that is designed to handle my mapping. According to what I've read, I should be able to create a package-info.java class in my domain hierarchy that contains the TypeDefs. Mine looks like this: @TypeDefs({ @TypeDef( defaultForType = ApplicationMessage.class, typeClass = ApplicationMessageType.class ) }) package mptstp.domain; import mptstp.domain

How to alter Column name in hibernate entity?

醉酒当歌 提交于 2019-12-10 11:38:57
问题 I have the following hibernate entity: @Table(name="tbl_template") @Entity @Audited public class StatementTemplate { private Long id; @Column(name = "template_name") private String templateName; ... } I changed the column name from template_name to stmt_name @Column(name = "stmt_name") private String templateName; It turned out that the instead of changing the column name hibernate added another column named stmt_name, now I have template_name as well as stmt_name I have following hibernate

Hibernate naming strategy

怎甘沉沦 提交于 2019-12-09 12:19:02
问题 I am building a REST webservice with Spring (Boot) and am trying to use hibernate as orm mapper without any xml configuration. I basically got it to work, but I am stuck with a configuration issue. I instantiate LocalContainerEntityManagerFactoryBean as @Bean in a @Configuration file. I set hibernate.ejb.naming_strategy as in the following example -> this seems to work for creating the tables if they do not exist (column names are camelCase like in my @Entity classes) but when a query is

HiLo generator strategy not working

时光总嘲笑我的痴心妄想 提交于 2019-12-09 04:20:19
问题 I am new to hibernate. What I am trying to do is use @CollectionId to generate an identifier for my Address class. I have used Collection interface for this. However when I use @GenericGenerator and set strategy to hilo, it throws an Exception. Here's my code: @Entity @Table(name = "USER_DETAILS") public class UserDetails { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int userId; private String userName; @ElementCollection @JoinTable(name="USER_ADDRESS", joinColumns=