| Author |
Message |
|
|
Post subject: [Closed] could not resolve property
Posted: Sep 26, 2006 - 12:41 PM
|
|
Registered Member


Joined: Apr 25, 2005
Posts: 119
|
|
I have a MySQL View with three string columns.
When I reverse engineer for Hibernate, I get the following:
| Code: | <hibernate-mapping>
<class name="com.col.hibernate.Ventypereg" table="ventypereg" catalog="test">
<composite-id name="id" class="com.col.hibernate.VentyperegId">
<key-property name="vendorName" type="java.lang.String">
<column name="VendorName" length="45" />
</key-property>
<key-property name="catagory" type="java.lang.String">
<column name="Catagory" length="45" />
</key-property>
<key-property name="region" type="java.lang.String">
<column name="Region" length="45" />
</key-property>
</composite-id>
</class>
</hibernate-mapping> |
And the following (fundemental) classes are created:
Abstract and concrete Ventypereg.java
VentyperegDAO
Abstract and concrete VentyperegId.java
I want to use query string:
"from Ventypereg as model where model.vendorName like ? AND model.catagory like ? and model. region like ?"
But I get the following exception:
org.hibernate.QueryException: could not resolve property: vendorName of: com.col.hibernate.Ventypereg [from com.col.hibernate.Ventypereg as model where model.vendorName like ? AND model.catagory like ? AND model.region = ?]
Also, when I stub the code and use VentyperegDAO.findByProperty(...) I get the same exception.
Can someone help here? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Sep 26, 2006 - 04:38 PM
|
|
Registered Member

Joined: Jan 06, 2004
Posts: 23824
|
|
The problem is that Hibernate cannot manage a table that doesn't contain a primary key, so what MyEclipse does is uses all the fields of the table to generate a primary key for each record. TO make your life easier, if you add a primary key to this table, and then re-reverse engineer it, your PK will be much simpler than name and the remaining fields will be registered as properties and your query should work fine.
If you don't do that, I'm not exactly sure how you only query for a part of a primary key, I don't think you can. |
_________________ Riyad
MyEclipse Support
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Sep 26, 2006 - 10:43 PM
|
|
Registered Member


Joined: Apr 25, 2005
Posts: 119
|
|
That doesn't work...it's a reverse engineered MySQL VIEW which doesn't support a primary key |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Sep 27, 2006 - 02:10 AM
|
|
Moderator


Joined: Feb 03, 2006
Posts: 1117
|
|
frankc01a,
You can works with view if composite id have unique , non-null values.Tyr with next query :
from Ventypereg as model where model.id.vendorName like ? AND model.id.catagory like ? and model. id.region like ?
I am not sure for findByProperty - Please, send use table script (you can generate one with MyEclipse's 'generate-> ddl), POJO and DAO classes
Thanks
Peco |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Sep 27, 2006 - 03:03 AM
|
|
Registered Member


Joined: Apr 25, 2005
Posts: 119
|
|
Thanks, that worked. As far as sending the other stuff, it is a view with three (3) columns that are text (Varchar(45)) from three different tables. None of the columns are primary key. |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Sep 27, 2006 - 11:54 AM
|
|
Moderator


Joined: Feb 03, 2006
Posts: 1117
|
|
Hibernate request that your id have non-null, unique values.When you have primary key database car about this, but if you use view (or table without PK) , you have to have correct values
for example, if your view (id values) have this :
null,'a','b'
it is invalid (null value) or
'a','b','c'
'a','b','c'
is invalid (non-unique values for id)
Best
Peco |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Sep 27, 2006 - 01:07 PM
|
|
Registered Member


Joined: Apr 25, 2005
Posts: 119
|
|
Yes, the view contains unique non-null values. It is working now that I added the "id." prefix to the attribute in the "model.id.xxx like ?" string.
Thanks for the help |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Oct 03, 2006 - 01:23 AM
|
|
Registered Member

Joined: Jan 06, 2004
Posts: 23824
|
|
Glad it's working. |
_________________ Riyad
MyEclipse Support
|
| |
|
|
|
 |
|
|