facebook

[Closed] could not resolve property

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #259251 Reply

    frankc01a
    Member

    I have a MySQL View with three string columns.

    When I reverse engineer for Hibernate, I get the following:

    <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?

    #259269 Reply

    Riyad Kalla
    Member

    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.

    #259294 Reply

    frankc01a
    Member

    That doesn’t work…it’s a reverse engineered MySQL VIEW which doesn’t support a primary key

    #259304 Reply

    Haris Peco
    Member

    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

    #259311 Reply

    frankc01a
    Member

    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.

    #259340 Reply

    Haris Peco
    Member

    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

    #259345 Reply

    frankc01a
    Member

    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

    #259740 Reply

    Riyad Kalla
    Member

    Glad it’s working.

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: [Closed] could not resolve property

You must be logged in to post in the forum log in