English 中文(简体)
hibern foreign key
原标题:hibernate foreign key

I have a Task table. It has a foreign key task_status_id.
I have a TaskStatus table. It has two primary keys: task_status_id and lang_id.
I have a LanguageType table. It has a primary key lang_id.

I want to know how to map this relationship in hibernate.

问题回答

I think this will probably do what you want:

@Entity
public class Task {
    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "task_id")
    private int id;
    @ManyToOne
    @JoinColumn(name = "task_status_id")
    TaskStatus status;
}

@Entity
public class TaskStatus {
    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "task_status_id")
    private int id;
    @ManyToOne
    @JoinColumn(name = "lang_id")
    LanguageType languageType;
}

@Entity
public class LanguageType {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "lang_id")
    private int id;
}




相关问题
Matrix to Represent a Triangle in Screen Space

So i have a set of four points in 3D Space. P1 [0, 0, 0] P2 [128, 0, 0] P3 [0, 128, 0] P4 [128, 128, 0] Which I m then projecting orthographically to the screen effectively giving me two ...

Using LINQ To SQL with multiple database tables

I have an employee class with as follows: public class Employee { public string FirstName { get; set; } public string LastName { get; set; } public string UserName { get; set; } ...

Mapping points from Euclician 2-space onto a Poincare disc

For some reason it seems that everyone writing webpages about Poincare discs is only concerned with how to represent lines and measure distances. I d like to morph a collection of 2D points (as ...

Fluent NHibernate, varbinary(max) and SQLite

I have a varbinary field in my sql server database that needs to be varbinary(max). I create my database with NHibernate and I use Fluent Nhibernate for my mappings. I also use SQLite for my unit ...

Javascript redirect

I am working with javascript and here is what I am trying to do: 1. Send a get request which looks like "http://localhost:8080/myapp/verify.htm?verifyId=Agkvhs" My requests reaches my verify.jsp in ...

热门标签