0

In already existing table structure inheritance I am adding a new column type (I cut some of the code)

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Account {
    ......        

    @Column                            // already existed column 
    private String name;               // get/set also applied

    @Column(length=20)                 // new added column 
    @Enumerated(EnumType.STRING)       // get/set also applied 
    private AccountType type; 

    ..........
}

@Entity
public User extends Account {
    ................                   // some other already existed fields
}

In my persistence.xml file I am using next strategy policy for DDL generation

property name="eclipselink.ddl-generation" value="drop-and-create-tables"

When DDL generation is processing the new added column type in Account table is successfully created, BUT for User table there is no such kind of column at all (the strategy is TABLE_PER_CLASS). I fixed that when i drop the database and created it again. After that the current generation of DLL was applied - type in User is also added as a column. Does someone "met" with such kind of issue ? I fixed with with drop and create of the DB but I am not sure that should be the strategy in same cases in future, specially for production DB

Thanks, Simeon Angelov

Simeon Angelov
  • 470
  • 4
  • 18

1 Answers1

3

DDL generation is for development not production. The problem you are seeing is because when the table already exists, it cannot be created with the new field. Drop and create or the "create-or-extend-tables" feature will work if you are adding to the tables as described here http://wiki.eclipse.org/EclipseLink/DesignDocs/368365

Chris
  • 20,138
  • 2
  • 29
  • 43
  • Hi Chris, As I see the only thing I should make is changing the persistence.xml file to My fie is the same one expect the DDL generation strategy. It's drop and create/ And in this case also the field was not added in the extended class. Am I understand correctly by the source you send me that I have to do only that thing with persistence/.xml file ? – Simeon Angelov Jan 30 '13 at 07:52
  • Yes, that and a redeploy of the app or call emf.refreshMetadata() to get it to reload as described in this post http://stackoverflow.com/questions/13372213/eclipselink-create-or-extend-tables-not-working-unknown-column You might also enable EclipseLink logging to see what might be going wrong as described here http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging – Chris Jan 30 '13 at 17:10