简体   繁体   中英

hibernate: How to map a variable as foreign key

is it possible to declare a variable Long documentID as Foreign key instead of the natural Document document ?Below the example:

@Entity
@Table("document")
class Document{
   ...
   @Id
   Long id;
   ...
}

@Entity
@Table("something")
class Something{
   ....
   //instead of
   @ManyToOne
   Document document;

   // this one with the appropriate annotations
   Long documentID;
   ...
}

Thanks in advance....

It seems a similar question have already appeared: Hibernate. Foreign key mapping by id

It is not recommended to work with hibernate in such manner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM