-->
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.  [ 4 posts ] 
Author Message
 Post subject: join table witha a view @nnotation based HELP
PostPosted: Wed Jun 23, 2010 10:14 am 
Newbie

Joined: Wed Dec 02, 2009 5:12 am
Posts: 3
Hi guys, as the title suggest i have some problems.

Now i will show the context where the problem live.

this is one my mapped class which represent a film entry

Code:
@Entity
@Table(name = "FILM", schema = "XXX")
public class Film implements java.io.Serializable {

   // Fields

   private Integer idfilm;
   private String title;
   private Remains remains;


   @Id
   @GeneratedValue(strategy=GenerationType.AUTO, generator = "SEQUENCE_FILM")
   @SequenceGenerator(name="SEQUENCE_FILM", sequenceName = "SEQUENCE_FILM")      
   @Column(name = "IDFILM", unique = true, nullable = false, precision = 22, scale = 0)
   public Integer getIdfilm() {
      return this.idfilm;
   }

   public void setIdfilm(Integer idfilm) {
      this.idfilm = idfilm;
   }


   @Column(name = "TITLE", length = 400)
   public String getTitle() {
      return this.titolofilm1;
   }

   public void setTitle(String title) {
      this.title = title;
   }
   
   @ManyToOne(fetch = FetchType.EAGER)   
   @JoinColumn(name="IDFILM")   
   public Remains getRemains() {
      return emains;
   }

   public void setRemains(Remains remains) {
      this.remains = remains;
   }






This class in theory is mapped to a view. And i have mapped this view as a normal table.
Code:
@Entity
@Table(name = "FILM", schema = "XXX")
public class Remains implements Serializable{
   private Integer day;
   private Film film;
   private Integer remainticket;
   
   
   @Column(name = "DAY", precision = 22, scale = 0)
   public Integer getDay() {
      return day;
   }
   
   public void setDay(Integer day) {
      this.day = day;
   }
      
   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "IDFILM")
   public Film getfilm() {
      return film;
   }
   
   public void setfilm(Film idfilm) {
      this.film = idfilm;
   }
   
   @Column(name = "REMAINTICKET", precision = 22, scale = 0)
   public Integer getRemainticket() {
      return remainticket;
   }
   
   public void setRemainticket(Integer remainticket) {
      this.remainticket = remainticket;
   }   
}




Now the point is: That i have mapped in the film class the object Remains, because i have the need, of knowing how many ticket it was remaining for a specific film.

The DBMS is Oracle 10g.

When my webserver start there i see this exception:
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: Remains
But the point is this table/view has no an ID.

My intent is only join the film table to a view, and getting the result.
So exist a way to tell to hibernate "forget everything about the identifier for this class" ??

add after.

I will create a composition of id as a work-around and now i have also this ex.
Repeated column in mapping for entity: com.Film column: IDFILM


Top
 Profile  
 
 Post subject: Re: join table witha a view @nnotation based HELP
PostPosted: Wed Jun 23, 2010 11:03 am 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 67
You have to define an ID. There is no workaround for that. As you're doing, define the ID as a composite of the unique columns.

The second problem is likely because of this:
Code:
@ManyToOne(fetch = FetchType.EAGER)   
   @JoinColumn(name="IDFILM")   
   public Remains getRemains() {
      return emains;
   }
I think you meant to use a different column name than "IDFILM".


Top
 Profile  
 
 Post subject: Re: join table witha a view @nnotation based HELP
PostPosted: Wed Jun 23, 2010 11:15 am 
Newbie

Joined: Wed Dec 02, 2009 5:12 am
Posts: 3
Thanks for fast reply

dkarr wrote:
You have to define an ID. There is no workaround for that. As you're doing, define the ID as a composite of the unique columns.


OK but my table is a view not a table.


dkarr wrote:
I think you meant to use a different column name than "IDFILM".

OK, mhhhh but in my view the column name is IDFILM....


Top
 Profile  
 
 Post subject: Re: join table witha a view @nnotation based HELP
PostPosted: Wed Jun 23, 2010 11:50 am 
Newbie

Joined: Wed Dec 02, 2009 5:12 am
Posts: 3
FIRST OF ALL thanks for your time.

The first problem is the anti-pattern copy and paste

Code:
@Entity
@Table(name = "FILM", schema = "XXX")
public class Remains implements Serializable{
   private Integer day;
   private Film film;
   private Integer remainticket;


The table name should be REMAINS.

So i apologize for that.

second based on hibernate need an id i found this solution:
http://www.experts-exchange.com/Programming/Languages/Java/J2EE/Q_23635082.html


Still thanks again to all


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.