Is it possible to map objects to part of an existing table?
Is it possible to map an object to only part of an existing table in a database? For example:
public class Account {
private Integer id;
private Integer accountNumber;
@Id
public Integer getId() {
return this.id;
开发者_开发百科 }
@Column(nullable=false)
public Integer getAccountNumber() {
return this.accountNumber;
}
}
In the database (just for the sake of the question):
Account
- id
- accountnumber
- lastmodified
- localbranchid
Yes, you can only map a portion of the columns in the database table to the Account
class (you simply just map the columns you are interested in), but if you ever have a need to insert new Account
s into the database and the unmapped columns have not-null constraints and no database default values, you will run into problems.
There shouldn't be any problems leaving out fields in relational mapping. There is really only one rule. If the class is to be updateable then you need to include all of the fields that make up the primary key so the updates can be propagated to the database.
精彩评论