Reputation: 332
I have two table like these :
1) table server_type :
server_type_id : number
server_type_name : nvarchar
2) table server :
server_id:number
server_IP:nvarchar2
servername :nvarchar2
server_type_id:number
I want to create server table with @OneToMany
with server_type_id
foreign key with referenced from server_type
I don't know how to do it , all of example and question here is opposite of this
Upvotes: 0
Views: 438
Reputation: 2066
Have you tried this ??. May be we can help if you can post some code :)
public class Server {
@ManyToOne
@JoinColumn(name = "server_type_id")
private ServerType serverType;
}
public class ServerType {
@OneToMany(mappedBy = "serverType")
private Collection<Server> servers;
}
Upvotes: 1
Reputation: 3653
Your @OneToMany
relationship can be achieved
In your case you can use second option and here is an example (you are talking about examples)
class UserDetails {
@OneToMany(mappedBy="user")
private Vehicle vehicle;
//Other fields
}
class Vehicle {
@ManyToOne
@JoinColumn(name="USER_ID")
private UserDrtails user;
//other fields
}
Upvotes: 1