facebook

slight hibernate problem w/derby

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

    dlittman
    Member

    I have tried the quick start exercise for hibernate with derby. I have a good connection to the db and can generate the hbm file (one table). The table has an id field [(integer not null generated always as identity (start with 1 increment by 1)] and a few varchars.

    The hbm file comes back ill-formed. It does not have the required “id” clause. I put in the id clause myself and the file is formed okay on rebuild.

    When I run the “HibernateTest” main the first message comes back okay (Hello from hibernate). It then gives the log4j message (which are okay to ignore according to the tutorial) and then gives a session factory error(blow).

    What am I doing wrong?

    Thanks in advance.

    OUTPUT–

    %%%% Error Creating SessionFactory %%%%
    org.hibernate.MappingException: Error reading resource: com/genuitec/hibernate/Tv.hbm.xml
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
    at com.genuitec.hibernate.SessionManager.currentSession(SessionManager.java:48)
    at com.genuitec.hibernate.HibernateTest.main(HibernateTest.java:16)
    Caused by: org.hibernate.PropertyNotFoundException: field not found: id
    at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:96)
    at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:103)
    at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:103)
    at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:111)
    at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:90)
    at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:78)
    at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:275)
    at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:360)
    at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:294)
    at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:236)
    at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:152)
    at org.hibernate.cfg.Configuration.add(Configuration.java:362)
    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:400)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
    … 7 more
    Exception in thread “main” java.lang.NullPointerException
    at com.genuitec.hibernate.SessionManager.currentSession(SessionManager.java:56)
    at com.genuitec.hibernate.HibernateTest.main(HibernateTest.java:16)

    #245294 Reply

    dlittman
    Member

    I had to remove the property clause in the cfg that referred to the id I put in by hand. I would still like to know why ME does not generate the id clause itself and returns an ill-formed cfg file.

    In this case it did not use the table id as the id and just put it in as a regular old column.

    Perhaps this has to do with the fact that there does not appear to be a derby dialect in the list of choices — I selected “Generic”. Is there a derby dialect available?

    #245743 Reply

    bobcoss
    Member

    Yes, you can use the derby dialect. I was using going through the tutorial yesterday, and selected the derby dialect.

    From my <hibernate-configuration> file.
    <property name=”dialect”>org.hibernate.dialect.DerbyDialect</property>

    Generated:
    <id name=”id” type=”integer”>
    <column name=”ID” />
    <generator class=”increment” />
    </id>

    Hope that helps.

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: slight hibernate problem w/derby

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