-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How do I Mapping Entity in JPA annotation
PostPosted: Mon Apr 17, 2017 6:20 am 
Newbie

Joined: Mon Apr 17, 2017 6:12 am
Posts: 2
First,I have 2 tables.
Quote:
t_user(id,name)
t_info(id,refer_id,refer_table,text)


if t_user.id = 7, i will find one record in table t_info, and the data is like this
[123,7,'t_user','something']

my Code is
Code:
@Entity
@Table(name = "t_user")
public class User implements Serializable {
@Id
protected String id;

@Column
protected String name;
}

@Entity
@Table(name = "t_info")
public class Info implements Serializable{
@Id
private String id;
@Column
private String referId;
@Column
private String referTable;
@Column
private String text;
}

@Entity
public class UserText extends User{
@OneToOne
@JoinColumn(name="id",referencedColumnName="refer_id")
private Info info;
}


I just want get two Repositories: Repository<User> and Repository<UserText>

Repository<User> for query and Repository<UserText> for save.

But i know 2 tables can not mapping 3 entities.
How to do?
Somebody help me,Thanks a lot....


Top
 Profile  
 
 Post subject: Re: How do I Mapping Entity in JPA annotation
PostPosted: Mon Apr 17, 2017 10:29 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You didn't mention what is the problem.


Top
 Profile  
 
 Post subject: Re: How do I Mapping Entity in JPA annotation
PostPosted: Mon Apr 17, 2017 9:35 pm 
Newbie

Joined: Mon Apr 17, 2017 6:12 am
Posts: 2
the problem is Hibernate will find "DTYPE" in UserText.
but table "t_user" didn't have such field.


Top
 Profile  
 
 Post subject: Re: How do I Mapping Entity in JPA annotation
PostPosted: Tue Apr 18, 2017 1:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The DTYPE is needed since you are using the default SINGLE_TABLE inheritance. Try switching to TABLE_PER_CLASS as illustrated in the following mapping:

Code:
@Entity
@Table(name = "t_user")
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class User implements Serializable {
    ...
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.