Hi,
I have problem with classes inheritance. I have table Register. Sometimes I don't need all it's columns, so I decided to map this table twice. I've created class
RegisterBasic {
RegisterBasic(){}
protected int registerNumber;
protected UserBasic owner;
public int getRegisterNumber() {
return registerNumber;
}
public void setRegisterNumber(int registerNumber) {
this.registerNumber = registerNumber;
}
public UserBasic getOwner() {
return owner;
}
public void setOwner(UserBasic owner) {
this.owner=(UserBasic)owner.clone();
}
}
And it's mapinig document looks like this:
<hibernate-mapping> <class name="connections.register.RegisterBasic" table="REGISTER"> <id name="registerNumber" column="REGISTER_NUM" type="integer"> <generator class="assigned"/> </id> <many-to-one name="owner" column="USER_ID" class="connections.user.UserBasic" not-null="true" foreign-key="FK_REG_USER"/> </class> </hibernate-mapping>
And than, it's classes extention:
class Register extends RegisterBasic{
Register(){}
private UnitClass unitClass;
public UnitClass getUnitClass() {
return unitClass;
}
public void setUnitClass(UnitClass unitClass) {
this.unitClass=(UnitClass)unitClass.clone();
}
And it's mapping:
}
<hibernate-mapping> <joined-subclass name="connections.register.Register" extends="connections.register.RegisterBasic"> <key column="registerNumber"/> <many-to-one name="unitClass" column="UNIT_CLASS" class="connections.fund.UnitClass" not-null="true" foreign-key="FK_REG_UNIT"/> </joined-subclass> </hibernate-mapping>
When I haven't used extention and just define again all variables and their functions again in class Register and in iRegister.hbm.xml file everything worked fine. But when I use this notation query
Query q = getSession().createQuery(" from Register " );
List result =q.list()
returns empty list. I really don't understand this. What is wrong with this notation?
|