Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programatically alter db table

Status
Not open for further replies.

pointertowhat

Programmer
Jan 13, 2009
22
0
0
US
I'm trying to write an update app which needs to modify a table in the embedded Derby Db, but I get

Code:
java.lang.IllegalArgumentException: node to traverse cannot be null!

The code concerned is:
Code:
Query q = this.entityManager1.createQuery("alter table jobrecords add column enginesize int not null default 0"); 

q.executeUpdate();

The actual sql is fine - I can execute it directly with no problems.
 
What persistence framework are you using?

Tim
 
Maybe using getNamedQuery instead od createQuery ...

But I'd first re-check the query itself

Cheers,
Dian
 
As a good practice, you should not be trying to alter tables using Hibernate, lest you would invalidate the table mapping.
Even if what you are trying to do works, how are you planning to update the POJO (mapped object for the table) with the new
property?

IMO, you should use Hibernate's capability of dynamically creating/updating the schema at startup.
 
I was planning to write a small update app, it will be started by the autorun feature on windows. It will connect with the database and modify the table required, then copy a new application jar to the system. This will have all the modified pojo's etc.

IMO, you should use Hibernate's capability of dynamically creating/updating the schema at startup.

I'm quite new to hibernate - how would I go about doing this without loosing the existing data?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top