Hi again.
Tired of trying a lot of different ways and always getting the same error, i decided to abandon the EntityManager and Annotations and try de HBM mapping files.
So, I mapped my District class in this way:
Code:
<hibernate-mapping>
<class name="model.District">
<composite-id class="model.DistrictPK" mapped="true">
<key-property name="id" column="D_ID" />
<key-property name="wId" column="D_W_ID" />
</composite-id>
<property name="name" type="string" column="D_NAME" length="10" />
<property name="street1" type="string" column="D_STREET_1" length="20" />
<property name="street2" type="string" column="D_STREET_2" length="20" />
<property name="city" type="string" column="D_CITY" length="20" />
<property name="state" type="string" column="D_STATE" length="2" />
<property name="zip" type="string" column="W_ZIP" length="9" />
<property name="tax" type="float" column="D_TAX" scale="0" precision="4" />
<property name="ytd" type="float" column="D_YTD" scale="12" precision="0" />
<property name="nextOId" type="long" column="D_NEXT_O_ID" />
<many-to-one name="warehouse" class="model.Warehouse" insert="false" update="false">
<column name="D_W_ID" />
</many-to-one>
</class>
</hibernate-mapping>
For my surprise, the same error appeared at this point:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
And this was worst because I havent mapped the Customer class, where I was used to find the problem.
The exception was: unable to find a getter for wId atribute. I certified my self and THERE WAS a getter for this attribute.
I thought, maybe there is a problem attribute`s name.
So I decided to try something that, at that time, didnt made any sense for me. I returned to the old project (EntityManager and Annotations) and changed the name of the attribute from
dId to
districtId in the Customer class. Generated the appropriate setters and getters and run a test. The same test:
Query q = em.createQuery("from Customer c where c.districtId=:districtId");
Result: That works!!!
So, the question is: Does this make sense for you?
Murilo