0
林有類似以下的超類:變化值
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected long id = "";
protected String firstname = "";
protected String lastname = "";
protected Address address = null;
// getter setter
你可以使用IM ANS TABLE_PER_CLASS
的InheritanceType
,我想保持這樣看。
現在,我得到兩個子類從Base
@Entity
public class Consulter extends Base {
// other fields
}
@Entity
public class Customer extends Base {
// other fields
}
繼承我現在創建像下面這樣的倉庫:
public interface Base_Repository extends JpaRepository<Base, Long> {
}
威爾JPA可以當我從數據庫返回正確的對象提供具體類型的ID?那麼類似的東西?
long id = 222;
Customer customer = customerRepository.findeOne(id);
Base base = baseRepository.findeOne(id);
boolean equals = customer.equals(((Customer) base));
而且還會有可能做類似的事情嗎?
Address address = new Address();
address.setStreet("space street 42");
address.setCountry("Trump Nation");
addressRepository.save(address);
Base base = baseRepository.findeOne(222);
base.setAddress(address);
baseRepository.save(base);
這項工作還是沒有可能嗎?
好的謝謝你的回答先生。 – Mulgard