-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Simple question/answer. How add extra element to xref table.
PostPosted: Thu Jul 27, 2006 4:20 pm 
Newbie

Joined: Thu Jul 27, 2006 1:14 pm
Posts: 3
Working from the hibernate tutorial:
http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html

I would like to move from the canned example of:
Code:
    _____________        __________________
   |             |      |                  |       _____________
   |   EVENTS    |      |   PERSON_EVENT   |      |             |
   |_____________|      |__________________|      |    PERSON   |
   |             |      |                  |      |_____________|
   | *EVENT_ID   | <--> | *EVENT_ID        |      |             |
   |  EVENT_DATE |      | *PERSON_ID       | <--> | *PERSON_ID  |
   |  TITLE      |      |__________________|      |  AGE        |
   |_____________|                                |  FIRSTNAME  |
                                                  |  LASTNAME   |
                                                  |_____________|

to adding a field 'KEYNOTE_SPEAKER' to the PERSON_EVENT cross ref table. Do I need to add an additional java class? Thanks in advance for your help!
Code:
    _____________        __________________
   |             |      |                  |       _____________
   |   EVENTS    |      |   PERSON_EVENT   |      |             |
   |_____________|      |__________________|      |    PERSON   |
   |             |      |                  |      |_____________|
   | *EVENT_ID   | <--> | *EVENT_ID        |      |             |
   |  EVENT_DATE |      | *PERSON_ID       | <--> | *PERSON_ID  |
   |  TITLE      |      |  KEYNOTE_SPEAKER |      |  AGE        |
   |_____________|      |__________________|      |  FIRSTNAME  |
                                                  |  LASTNAME   |
                                                  |_____________|


How should my tables/classes change from below to support this?

Person.java
Code:
public class Person {

    private Long id;
    private int age;
    private String firstname;
    private String lastname;
    private Set events = new HashSet();

    public Set getEvents() {
      return events;
   }

   public void setEvents(Set events) {
      this.events = events;
   }

   public Person() {}

   public int getAge() {
      return age;
   }

   public void setAge(int age) {
      this.age = age;
   }

   public String getFirstname() {
      return firstname;
   }

   public void setFirstname(String firstname) {
      this.firstname = firstname;
   }

   public String getLastname() {
      return lastname;
   }

   public void setLastname(String lastname) {
      this.lastname = lastname;
   }

   public Long getId() {
      return id;
   }

   private void setId(Long id) {
      this.id = id;
   }
}

Person.hbm.xml
Code:
<hibernate-mapping>

    <class name="events.Person" table="PERSON">
        <id name="id" column="PERSON_ID">
            <generator class="native"/>
        </id>
        <property name="age"/>
        <property name="firstname"/>
        <property name="lastname"/>
       
        <set name="events" table="PERSON_EVENT">
           <key column="PERSON_ID"/>
           <many-to-many column="EVENT_ID" class="events.Event"/>
       </set>
    </class>

</hibernate-mapping>



Event.java
Code:
public class Event {
    private Long id;

    private String title;
    private Date date;

    public Event() {}

    public Long getId() {
        return id;
    }

    private void setId(Long id) {
        this.id = id;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}


Event.hbm.xml
Code:
<hibernate-mapping>

    <class name="events.Event" table="EVENTS">
        <id name="id" column="EVENT_ID">
            <generator class="native"/>
        </id>
        <property name="date" type="timestamp" column="EVENT_DATE"/>
        <property name="title"/>
    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 8:19 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Yes, you need to implement a class for PERSON_EVENT. You can avoid mapping it explicitly by using composite-element class="PersonEvent" in Events' collection mapping.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Please post solution
PostPosted: Mon Sep 18, 2006 5:24 pm 
Beginner
Beginner

Joined: Tue Sep 13, 2005 4:54 pm
Posts: 34
Tenwit,
This is exactly the problem I am facing. Could you please write down what you suggested for his answer? I understand in theory what you have given for the answer but I cannot seem to find a concrete example of it.

I know it will be obvious how to do it after I know the solution, but my Hibernate experience is not enough that I can devise the mapping combination on my own.

Thank you,
Ty


Top
 Profile  
 
 Post subject: Please post solution
PostPosted: Mon Sep 18, 2006 5:24 pm 
Beginner
Beginner

Joined: Tue Sep 13, 2005 4:54 pm
Posts: 34
Tenwit,
This is exactly the problem I am facing. Could you please write down what you suggested for his answer? I understand in theory what you have given for the answer but I cannot seem to find a concrete example of it.

I know it will be obvious how to do it after I know the solution, but my Hibernate experience is not enough that I can devise the mapping combination on my own.

Thank you,
Ty


Top
 Profile  
 
 Post subject: Please post solution
PostPosted: Mon Sep 18, 2006 5:25 pm 
Beginner
Beginner

Joined: Tue Sep 13, 2005 4:54 pm
Posts: 34
Tenwit,
This is exactly the problem I am facing. Could you please write down what you suggested for his answer? I understand in theory what you have given for the answer but I cannot seem to find a concrete example of it.

I know it will be obvious how to do it after I know the solution, but my Hibernate experience is not enough that I can devise the mapping combination on my own.

Thank you,
Ty


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 18, 2006 5:29 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The second example in section 8.2 of the ref docs is the concrete example for which you are looking.

I assume that you don't need help with the alternative method, simply mapping the join table as a class. That one is straight-forward.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: answering my own question...
PostPosted: Mon Sep 18, 2006 9:51 pm 
Newbie

Joined: Thu Jul 27, 2006 1:14 pm
Posts: 3
...well now I can say I know a lot more about hibernate and can answer my own question I guess...so for the mapping...

So first the theory. If you have that extra property keynote_speaker then you can create a new class to represent that and persist it. ( I say can because there is probably some other way, I don't know it, I'm just telling you the way that I do this, you can do it the same way, since I know this works and when you become a master come and answer your own question with something slicker! ;)

So now we have 3 java classes. Let me call the third class Attendee. So the three classes we now have are:

Event, Attendee and Person

Instead of using the attribute KeynoteSpeaker, lets set the attribute to be role which can take the values of: "Keynote Speaker", "Paid Participant", or "Volunteer". That's a bit more realistic.

So each Event is going to have a 1:n mapping with Attendee(s), and each Attendee is going to have a 1:1 mapping with a Person.

Now I you'll have three mapping files and I call the database tables associated with these Classes the plural of the Class name. So three tables called:

Events, Attendees and People

So the Event class will look like this:

private Set attendees;

you can also use a List if you don't have the requirement that you can only have 1 copy of any given attendee, that would look like:

private List attendees;

of course you need getters and setters for this property.

Now the mapping file will look like this:

<set name="attendees" inverse="true" lazy="true"
cascade="all-delete-orphan">
<key column="event_id" />
<one-to-many class="Attendee" />
</set>

or if you are using a list:

<bag name="attendees" inverse="true" lazy="true"
cascade="all-delete-orphan">
<key column="event_id" />
<one-to-many class="Attendee" />
</bag>

Now the Attendee java class will look like the following.

private Event event;
private Person person;

And it's mapping file will have an entry like the following:

<many-to-one name="event" column="event_id" not-null="true"/>
<many-to-one name="person" column="person_id" not-null="true"/>

we say not-null because we don't ever have an attendee without an event!

So now why do we have many-to-one on the person table? Well speak it out this way...

One person ( the one side of the many-to-one ) can be an Attendee for multiple ( the many side of the many-to-one ) events. So just think about the foreign key in the Attendee table. The foreign key is person_id and it is going to show up many times in the table thus many-to-one whereas that same id is only going to show up once in the people table.

Now lets think about the Person class...they'll probably want to have a list of events that they are attending right? Maybe they'll want to know for which events they are a KeynoteSpeaker so we could make a relationship between a Person and Attendee like the following

Person.java
...
private Set attendances;

Person.hbm.xml

<set name="attendances" inverse="true" lazy="true"
cascade="all-delete-orphan">
<key column="person_id" />
<one-to-many class="Attendee" />
</set>

I think that should all work now...

good luck...


Top
 Profile  
 
 Post subject: Followed Your Example--Still Can't Make It work
PostPosted: Tue Sep 19, 2006 2:03 pm 
Beginner
Beginner

Joined: Tue Sep 13, 2005 4:54 pm
Posts: 34
ftravers,
Thank you kindly for replying. I following what I thought were your method but I have not had any success. Can you please look at what I have here and see where I've gone astray?

Thank you!
Ty


Person.java and mapping:
Image

Image

Attendees.java and mapping:
Image
Image

Events.java and mapping:
Image
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 5:25 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Diagnosis is easier when the problem is understood. What isn't working? Are you getting a mapping exception somewhere? A exception at run-time? Is it apparently working but not saving to your DB? Explain what the problem is.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: My Apologies: stack trace included
PostPosted: Tue Sep 19, 2006 5:53 pm 
Beginner
Beginner

Joined: Tue Sep 13, 2005 4:54 pm
Posts: 34
Tenwit,
Pardon the absence. Here is the exception I get with the above configuration.

Thank you,
Ty


Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.


C:\>cd C:\_HibernateHelloWorld\HelloWorldHibernate

C:\_HibernateHelloWorld\HelloWorldHibernate>ant run
Buildfile: build.xml

clean:
[delete] Deleting directory C:\_HibernateHelloWorld\HelloWorldHibernate\bin
[mkdir] Created dir: C:\_HibernateHelloWorld\HelloWorldHibernate\bin

copy-resources:
[copy] Copying 6 files to C:\_HibernateHelloWorld\HelloWorldHibernate\bin
[copy] Copied 4 empty directories to 2 empty directories under C:\_HibernateHelloWorld\HelloWorldHibernate\bin

compile:
[javac] Compiling 7 source files to C:\_HibernateHelloWorld\HelloWorldHibernate\bin
[javac] Note: C:\_HibernateHelloWorld\HelloWorldHibernate\src\events\EventManager.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.

run:
[java] In 'getPerson'
[java] 15:49:07,735 INFO Environment:474 - Hibernate 3.1
[java] 15:49:07,735 INFO Environment:504 - hibernate.properties not found
[java] 15:49:07,745 INFO Environment:520 - using CGLIB reflection optimizer
[java] 15:49:07,745 INFO Environment:550 - using JDK 1.4 java.sql.Timestamp handling
[java] 15:49:07,815 INFO Configuration:1257 - configuring from resource: /hibernate.cfg.xml
[java] 15:49:07,815 INFO Configuration:1234 - Configuration resource: /hibernate.cfg.xml
[java] 15:49:07,935 INFO Configuration:460 - Reading mappings from resource: events/Event.hbm.xml
[java] 15:49:08,076 INFO HbmBinder:266 - Mapping class: events.Event -> EVENT
[java] 15:49:08,106 INFO Configuration:460 - Reading mappings from resource: events/Person.hbm.xml
[java] 15:49:08,156 INFO HbmBinder:266 - Mapping class: events.Person -> PERSON
[java] 15:49:08,156 INFO Configuration:460 - Reading mappings from resource: events/Attendees.hbm.xml
[java] 15:49:08,206 INFO HbmBinder:266 - Mapping class: events.Attendees -> ATTENDEE
[java] 15:49:08,236 INFO Configuration:1368 - Configured SessionFactory: null
[java] 15:49:08,236 INFO Configuration:1014 - processing extends queue
[java] 15:49:08,236 INFO Configuration:1018 - processing collection mappings
[java] 15:49:08,236 INFO HbmBinder:2233 - Mapping collection: events.Event.attendees -> ATTENDEE
[java] 15:49:08,246 INFO HbmBinder:2233 - Mapping collection: events.Person.attendances -> ATTENDEE
[java] 15:49:08,246 INFO Configuration:1027 - processing association property references
[java] 15:49:08,246 INFO Configuration:1049 - processing foreign key constraints
[java] 15:49:09,198 WARN RootClass:210 - composite-id class does not override equals(): events.Attendees
[java] 15:49:09,208 WARN RootClass:215 - composite-id class does not override hashCode(): events.Attendees
[java] 15:49:09,218 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
[java] 15:49:09,218 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
[java] 15:49:09,218 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
[java] 15:49:09,228 INFO DriverManagerConnectionProvider:80 - using driver: net.sourceforge.jtds.jdbc.Driver at URL: jdbc:jtds:sqlserver://local
host:1433;databaseName=FREYA_DB
[java] 15:49:09,228 INFO DriverManagerConnectionProvider:86 - connection properties: {user=freya, password=****}
[java] 15:49:10,742 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server, version: 09.00.1399
[java] 15:49:10,742 INFO SettingsFactory:78 - JDBC driver: jTDS Type 4 JDBC Driver for MS SQL Server and Sybase, version: 1.2
[java] 15:49:10,772 INFO Dialect:100 - Using dialect: org.hibernate.dialect.SQLServerDialect
[java] 15:49:10,852 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
[java] 15:49:10,852 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or t
ransactional second-level cache is not recommended)
[java] 15:49:10,852 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
[java] 15:49:10,852 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
[java] 15:49:10,862 INFO SettingsFactory:144 - Scrollable result sets: enabled
[java] 15:49:10,862 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): enabled
[java] 15:49:10,862 INFO SettingsFactory:160 - Connection release mode: auto
[java] 15:49:10,872 INFO SettingsFactory:187 - Default batch fetch size: 1
[java] 15:49:10,872 INFO SettingsFactory:191 - Generate SQL with comments: disabled
[java] 15:49:10,872 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
[java] 15:49:10,872 INFO SettingsFactory:338 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[java] 15:49:10,882 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
[java] 15:49:10,882 INFO SettingsFactory:203 - Query language substitutions: {}
[java] 15:49:10,882 INFO SettingsFactory:209 - Second-level cache: enabled
[java] 15:49:10,882 INFO SettingsFactory:213 - Query cache: disabled
[java] 15:49:10,882 INFO SettingsFactory:325 - Cache provider: org.hibernate.cache.NoCacheProvider
[java] 15:49:10,882 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
[java] 15:49:10,882 INFO SettingsFactory:237 - Structured second-level cache entries: disabled
[java] 15:49:10,902 INFO SettingsFactory:257 - Echoing all SQL to stdout
[java] 15:49:10,902 INFO SettingsFactory:264 - Statistics: disabled
[java] 15:49:10,902 INFO SettingsFactory:268 - Deleted entity synthetic identifier rollback: disabled
[java] 15:49:10,902 INFO SettingsFactory:283 - Default entity-mode: POJO
[java] 15:49:11,123 INFO SessionFactoryImpl:155 - building session factory
[java] 15:49:12,145 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
[java] 15:49:12,145 INFO SessionFactoryImpl:432 - Checking 0 named queries
[java] Hibernate: select person0_.PERSON_ID as PERSON1_1_0_, person0_.age as age1_0_, person0_.firstname as firstname1_0_, person0_.lastname as l
astname1_0_ from PERSON person0_ where person0_.PERSON_ID=?
[java] Hibernate: select attendance0_.PERSON_ID as PERSON2_1_, attendance0_.EVENT_ID as EVENT1_1_, attendance0_.EVENT_ID as EVENT1_2_0_, attendan
ce0_.PERSON_ID as PERSON2_2_0_, attendance0_.NAME as NAME2_0_ from ATTENDEE attendance0_ where attendance0_.PERSON_ID=?
[java] 15:49:12,466 INFO DefaultLoadEventListener:95 - Error performing load command
[java] Exception in thread "main" org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_ref
lection_optimizer=false for more info) setter of events.Attendees.setEvent
[java] at org.hibernate.tuple.PojoComponentTuplizer.setPropertyValues(PojoComponentTuplizer.java:101)
[java] at org.hibernate.type.ComponentType.setPropertyValues(ComponentType.java:312)
[java] at org.hibernate.type.ComponentType.resolve(ComponentType.java:530)
[java] at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:229)
[java] at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1088)
[java] org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for
more info) setter of events.Attendees.setEvent
[java] at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:553)
[java] at org.hibernate.tuple.PojoComponentTuplizer.setPropertyValues(PojoComponentTuplizer.java:101)
[java] at org.hibernate.type.ComponentType.setPropertyValues(ComponentType.java:312)
[java] at org.hibernate.type.ComponentType.resolve(ComponentType.java:530)
[java] at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:229)
[java] at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1088)
[java] at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:553)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:689)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
[java] at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
[java] at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
[java] at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
[java] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.ja
va:60)
[java] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1593)
[java] at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
[java] at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:791)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:228)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:689)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
[java] at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
[java] at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
[java] at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
[java] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.ja
va:60)
[java] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1593)
[java] at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
[java] at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:791)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:228)
[java] at org.hibernate.loader.Loader.loadEntity(Loader.java:1782)
[java] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
[java] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2729)
[java] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
[java] at org.hibernate.loader.Loader.loadEntity(Loader.java:1782)
[java] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
[java] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2729)
[java] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
[java] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
[java] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
[java] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:82)
[java] at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:809)
[java] at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:771)
[java] at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:62)
[java] at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
[java] at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
[java] at events.Person$$EnhancerByCGLIB$$d766908a.getFirstname(<generated>)
[java] at events.EventManager.getPerson(Unknown Source)
[java] at events.EventManager.main(Unknown Source)
[java] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
[java] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
[java] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:82)
[java] at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:809)
[java] at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:771)
[java] at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:62)
[java] at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
[java] Caused by: net.sf.cglib.beans.BulkBeanException: java.lang.Long
[java] at events.Attendees$$BulkBeanByCGLIB$$c30401f6.setPropertyValues(<generated>)
[java] at org.hibernate.tuple.PojoComponentTuplizer.setPropertyValues(PojoComponentTuplizer.java:97)
[java] ... 31 more
[java] Caused by: java.lang.ClassCastException: java.lang.Long
[java] ... 33 more
[java] at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
[java] at events.Person$$EnhancerByCGLIB$$d766908a.getFirstname(<generated>)
[java] at events.EventManager.getPerson(Unknown Source)
[java] at events.EventManager.main(Unknown Source)
[java] Caused by: net.sf.cglib.beans.BulkBeanException: java.lang.Long
[java] at events.Attendees$$BulkBeanByCGLIB$$c30401f6.setPropertyValues(<generated>)
[java] at org.hibernate.tuple.PojoComponentTuplizer.setPropertyValues(PojoComponentTuplizer.java:97)
[java] ... 31 more
[java] Caused by: java.lang.ClassCastException: java.lang.Long
[java] ... 33 more
[java] Java Result: 1

BUILD SUCCESSFUL
Total time: 11 seconds
C:\_HibernateHelloWorld\HelloWorldHibernate>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 6:01 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That's an easy one. You forgot the "public Long getId()" and "public void setId(Long)" methods in the Event and Person classes.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 6:10 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Note the case sensitivity. It'll be getID/setID for Event, and getId/setId for Person. That's determined by the name attribute of the id element in the relevant mappings.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Will fix IDs
PostPosted: Tue Sep 19, 2006 6:33 pm 
Beginner
Beginner

Joined: Tue Sep 13, 2005 4:54 pm
Posts: 34
Tenwit,
Thank you. I will fix the IDs.

Otherwise, does the mapping look okay? I don't want to fix the IDs only to find the mapping is still screwed up.

Thank you,
Ty


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 6:39 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Why not? You can't expect it all to work perfectly after you fix one bug.

It looks ok, but I'm not being paid enough to test it for you.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Final Working Solution (For other newbies)
PostPosted: Wed Sep 20, 2006 10:01 am 
Beginner
Beginner

Joined: Tue Sep 13, 2005 4:54 pm
Posts: 34
Tenwit,
Thank you again, that was the correct, final solution. Thank you for your help. I have documented how this works so my team will not need to bother the forums again.

But for somebody coming after me, here is what actually worked:

Person.java

Image

Person.hbm.xml

Image


Event.java

Image

Event.hbm.xml

Image


Attendees.java

Image

Attendees.hbm.xml [The mapping in here is most critical, although the others have to be setup correctly too, obviously.]

Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.