-->
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.  [ 12 posts ] 
Author Message
 Post subject: mysql views
PostPosted: Thu Jun 14, 2007 9:04 am 
Newbie

Joined: Thu Jun 14, 2007 9:01 am
Posts: 4
Location: Sevilla
I am trying to create an entity from a mysql view. Is it possible? JBoss writes that table 'Prueba' not exists because Prueba is not a table. Prueba is a View of two tables. I want to display a list of data from two tables join by id. Thanks and sorry for my English.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 9:34 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

I think you should just be able to create a normal entity and use the @Table annotation, like so:

Code:
@Entity
@Table(name = "<your view name>")
public class MyClass implements Serializable {
.......
}


I have not tested this but it should work (hopefully)

Cheers,

Andy

p.s. Your English is pretty good ;-)

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 9:45 am 
Newbie

Joined: Thu Jun 14, 2007 9:01 am
Posts: 4
Location: Sevilla
Thanks for the answer. I had tried this but jboss writes that table **** not exists. I look for @View annotation but i don't find nothing similar.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 10:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
your view is probably in the wrong schema, or the wrong database :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 10:46 am 
Newbie

Joined: Thu Jun 14, 2007 9:01 am
Posts: 4
Location: Sevilla
thanks for the reply. The view is in the correct schema. i am using seam-gen that generates all the entities for all the tables and views in my schema. The views' entities don't work (compilation error 'table not found'). i don't understand it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 2:00 pm 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Can you post a sample entity and the view's DDL, this should hopefully shed some more light on the problem.

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 2:15 am 
Newbie

Joined: Thu Jun 14, 2007 9:01 am
Posts: 4
Location: Sevilla
Tables and View are in consultas schema.
Table secciones.
seccion INTEGER (PK)
logo VARCHAR(45)
linea INTEGER
bienvenida TEXT
...

Table codigos.
seccion INTEGER (PK)
codIni INTEGER
codFin INTEGER
codActual INTEGER
name VARCHAR (45)

View Prueba.
VIEW `prueba` AS select `s`.`seccion` AS `seccion`,`codigos`.`name` AS `name`,`s`.`linea` AS `linea`,`codigos`.`codIni` AS `codIni`,`codigos`.`codFin` AS `codFin`,`codigos`.`codActual` AS `codActual` from (`secciones` `s` join `codigos` on((`s`.`seccion` = `codigos`.`seccion`)))

@Entity
@Table(name = "prueba", catalog = "consultas")
public class Codigos implements Serializable {

private int seccion;
private int codIni;
private int codFin;
private int codActual;
private int linea;
private String name;

/get and set methods are defined.

When JBoss is starting writes 'Table Prueba is not defined'.

Thanks for help me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 9:02 am 
Newbie

Joined: Wed Feb 27, 2008 1:55 pm
Posts: 3
Location: Germany
Hi! I'm currently faceing the same problem with a View in Oracle - the tables and views are in the same schema but when i try to map a view with @Entity(name ="XYZ") I get the message "table not found".

Has anyone found a solution for mapping views?

Thanks,

altes-kind


Top
 Profile  
 
 Post subject: View Handling is a bug in Hibernate Validator
PostPosted: Sat Mar 01, 2008 1:46 pm 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Quote:
your view is probably in the wrong schema, or the wrong database
.
Emmanuel should know it better. If you let run the Hibernate validate tool at server startup (which is a good thing!), it complains about not finding the table (which in fact doesn't exist) because it doesn't look for database views . The only possible thing is to NOT run the validation - which is a bad thing.

I read in the release notes for V3.2.6 that this a Jira documented bug and it is fixed with this release. I didn't test it until now.

I also think that there should be a @View annotation - even it works with @Table it should be made explicit that we are dealing with a view and not with a table.

Carlo


Top
 Profile  
 
 Post subject: Re: View Handling is a bug in Hibernate Validator
PostPosted: Sat Mar 08, 2008 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
carlolf wrote:
Quote:
I also think that there should be a @View annotation - even it works with @Table it should be made explicit that we are dealing with a view and not with a table.


In smart DBs, there is not much fo a difference between a view and a table. No need to separate the concepts.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: View Handling is a bug in Hibernate Validator
PostPosted: Wed Mar 12, 2008 5:03 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
emmanuel wrote:
In smart DBs, there is not much fo a difference between a view and a table. No need to separate the concepts.


Maybe, and maybe that "@View" is not needed. The problem that I noticed is: Hibernate's validation task that's running on server startup on (which is a good thing!) says that a table cannot be found if I map an entity to a view! So I had to disable this validation (which is a bad thing!).

I think there exists a Jira entry on this error.

Carlo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 2:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Vote on the JIRA entry, Max will look at it.

_________________
Emmanuel


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