persistence@glassfish.java.net

RE: adding new attributes to classes won't create the respective columns in database

From: Eve Pokua <gorgeous65_at_msn.com>
Date: Fri, 4 Jul 2008 15:57:53 +0100

Hello everyone,
 
I was experiencing the same issues with JDbase, the Java database that comes with
the application server. However, this was not the same with MS SQL server 2000. Even
with 'drop and create' setup, the database and tables was in-touch. So this only is effective
on certain DBMS.
 
Sorry, this does not help your problem but I thought I make a point.
 
eve



> Date: Thu, 19 Jun 2008 06:41:19 -0700> From: jamesssss@yahoo.com> To: persistence@glassfish.dev.java.net> Subject: Re: adding new attributes to classes won't create the respective columns in database> > > The table creation support is only meant for rapid prototyping, not for> production data.> > The table creation "create" option will only create the tables if they are> missing. You must use "drop and create" to recreate the database. There is> no support for altering, but you can do this yourself through your databases> DDL.> > > snowstone wrote:> > > > Hello everybody:> > I'm using JPA-Toplink in a desktop application, linked to a Postgres DB.> > I'm following a course and its exercises. I created the tables from the> > code without problems. The problems come whenever I want to add more> > attributes to the already existing classes (In the next exercise we create> > relationships between classes made with new attributes).> > > > Having the 2 classes:> > @Entity> > public class Autor implements Serializable {> > @Id> > private String nombre;> > private String correo;> > @OneToMany(mappedBy = "autor")> > private Collection<Mensaje> mensajes = new HashSet<Mensaje>();> > > > //This is the new attribute for the new relationship > > @OneToMany(mappedBy="autor")> > private Collection<PaginaHtml> paginas = new HashSet<PaginaHtml>();> > ...}> > > > @Entity> > public class PaginaHtml implements Serializable {> > > > private static final long serialVersionUID = 1L;> > > > @Id> > private String nombreFichero; > > @Temporal(value = TemporalType.DATE)> > private Calendar creacion;> > @Lob> > private String html;> > private Encoding encoding;> > private String extensión; > > > > //This is the new attribute for the new relationship > > @ManyToOne> > private Autor autor;> > ...}> > > > And the code to link both:> > > > public void addAutorPagina(){> > PaginaHtmlDAO phDAO = new PaginaHtmlDAO (em); > > AutorDAO autDAO = new AutorDAO (em);> > List<PaginaHtml> listaPag = new ArrayList();> > List<Autor> listaAut = new ArrayList();> > > > em.getTransaction().begin(); //3> > listaPag = phDAO.listaPaginas();> > listaAut = autDAO.listaAutores();> > > > if (!listaPag.isEmpty() && !listaAut.isEmpty()){> > listaPag.get(0).setAutor(listaAut.get(0)); //Update relationship> > from propietary end (PaginaHtml)> > listaAut.get(0).addPagina(listaPag.get(0)); //Update> > relationship from other end> > > > }> > em.getTransaction().commit(); //4 > > > > }> > > > Whenever I do the commit, I get the error from Postgre:> > "Internal Exception: org.postgresql.util.PSQLException: ERROR: no existe> > la columna «autor_nombre»" (The column "autor_nombre" doesn't exist.> > > > This is done with my Table Generation Strategy (from the PU) set to> > "Create".> > If I change this strategy to "Drop and Create", I don't get any errors,> > and the column "autor_nombre" is created in the table "paginahtml".> > > > But for me this is not a solution, since when I drop the table I loose all> > the data...> > > > is that the correct procedure? Every time you change attributes in classes> > you have to backup your DB, change to "Drop and Create", and then get back> > the "old data".> > > > Or what am I doing wrong?> > > > Tank you very much for your time,> > > > Pere Serrano> > > > > > > -----> ---> http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland > http://www.eclipse.org/eclipselink/> EclipseLink , http://www.oracle.com/technology/products/ias/toplink/> TopLink > Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink , > http://wiki.oracle.com/page/TopLink TopLink > Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , > http://www.nabble.com/EclipseLink-f26430.html EclipseLink > Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence > -- > View this message in context: http://www.nabble.com/adding-new-attributes-to-classes-won%27t-create-the-respective-columns-in-database-tp17986273p18009290.html> Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.>
_________________________________________________________________
Play and win great prizes with Live Search and Kung Fu Panda
http://clk.atdmt.com/UKM/go/101719966/direct/01/