-->
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.  [ 2 posts ] 
Author Message
 Post subject: Eager, CollectionOfElements, PersistentBag, and Arraylist
PostPosted: Thu Jun 19, 2008 1:40 am 
Newbie

Joined: Fri Jan 18, 2008 1:59 pm
Posts: 10
I have the following class:

Code:
@Entity
@Table(name = "locations")
public class Location {
   @Id
   private int id;
...
   @CollectionOfElements(fetch = FetchType.EAGER)
   @JoinTable(
      name = "types_with_location_view",
      joinColumns = @JoinColumn(name = "location_id")
   )
   @Column(name = "type")
   @Basic(fetch = FetchType.EAGER)
   private List<String> types;
...
}

Which corresponds to the following database schema:

Code:
CREATE TABLE locations (
  id int(10) unsigned NOT NULL auto_increment,
  ...
  PRIMARY KEY  (`id`)
)

CREATE TABLE locations_types (
  location_id varchar(16) NOT NULL,
  type_id smallint(5) unsigned NOT NULL,
  PRIMARY KEY  (`location_id`,`type_id`)
)

CREATE TABLE types (
  id smallint(5) unsigned NOT NULL auto_increment,
  type varchar(10) NOT NULL,
  PRIMARY KEY  (`id`)
)

My problem is when I get a Location using a Hibernate query, the Location.types instance is a PersistentBag. I thought setting the fetch type to EAGER would force hibernate to use an ArrayList or something.

I can't have any Hibernate specific classes in my Location object after Hibernate returns it back to me. Can anyone help me out here?

Thanks,
Eric


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 19, 2008 1:44 am 
Newbie

Joined: Fri Jan 18, 2008 1:59 pm
Posts: 10
Here's the sql for the view mentioned in the Java annotation:

Code:
CREATE VIEW types_with_location
AS
select
   lt.location_id,
   lt.type_id,
   t.type
from
   types t join
   locations_types lt on ( t.id = lt.type_id )


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

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.