alter table

#1

Hi:

After a table built by real data, how to alter table structure, such as:

alter table add column ...

alter table add index ...

TIA

Institute of Computer Technologies
#2

There are no tables is ObjectDB. Anyway,

> alter table add column ...

This is automatic - just change your class (see Database Schema Evolution in the manual).

> alter table add index ...

Add the index definition and rebuild the database using the Object Doctor (see also this feature request).

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Thanks for the comments of "add column";

but I can not find anything about "add index" in the links you given.

TIA

Institute of Computer Technologies
#4

You can add a new index to an existing entity class anytime.

But if that class has already instances in the database - the index will not be active (used in queries) until you rebuild the database (see the links in #2).

Update: Starting ObjectDB 2.6.6 new indexes are automatically built and activated in the background.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#5

so, your strategy is changing class first and rebuilding DB by this command?

> java -cp objectdb.jar com.objectdb.Doctor old.odb new.odb"

Thanks,

It is better if there was an elegant way like "alter table ...".

Institute of Computer Technologies
#6

>> Add the index definition and rebuild the database using the Object Doctor 

I'm not sure after index changing, how the command know the index changing?

java -cp objectdb.jar com.objectdb.Doctor old.odb new.odb
Institute of Computer Technologies
#7

I'm not sure the index changing how to inference the command:

> java -cp objectdb.jar com.objectdb.Doctor old.odb new.odb

Besides, I've stocked more than an hour, after the above command for a 10GB DB

.................................................. 9200MB
.................................................. 9300MB
.................................................. 9400MB
.................................................. 9500MB
.................................................. 9600MB
.................................................. 9700MB
.................................................. 9800MB
..................... 9843MB (total)
Institute of Computer Technologies
#8

Actually it rebuilds the entire database and all the indexes, not just one index.

It does take time, but currently this is the solution.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#9

I want to know how the command use the modified class (with @index), it has no knowledge about the .java or .class information.!

BTW, "describe table xxx" will show what index a column has, but how objectdb do the same thing?

TIA

Institute of Computer Technologies
#10

> I want to know how the command use the modified class (with @index), it has no knowledge about the .java or .class information.!

That is a good point. After changing the class and before running the Doctor - the class has to be added to the database. This is done automatically if you open the database in your application and the new class is available in the classpath, but this is indeed a step that has to be done. Alternatively, I think that you may run the Doctor specifying a classpath that contains the new class.

> BTW, "describe table xxx" will show what index a column has, but how objectdb do the same thing?

In the Explorer of ObjectDB 2.3 (not released yet) you will be able to see the indexes.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#11

I ever make a class of Meta. Then I generalize it to MetaSogou, Meta only has additional functions. Now, I restore the Meta to independent. But I get error like:

Exception in thread "main" [ObjectDB 2.2.9_04] javax.persistence.RollbackException
Failed to commit transaction: Failed to get reference value of field field image.MetaSogou.iHei using reflection (error 613)
 at com.objectdb.jpa.EMImpl.commit(EMImpl.java:277)
 at test.testString.main(testString.java:55)
Caused by: javax.persistence.PersistenceException: com.objectdb.o.UserException: Failed to get reference value of field field image.MetaSogou.iHei using reflection
 at com.objectdb.o._PersistenceException.b(_PersistenceException.java:47)
 at com.objectdb.o.JPE.g(JPE.java:140)
 at com.objectdb.o.JPE.g(JPE.java:78)
 ... 4 more
Caused by: com.objectdb.o.UserException: Failed to get reference value of field field image.MetaSogou.iHei using reflection
 at com.objectdb.o.MSG.d(MSG.java:74)
 at com.objectdb.o.UMR.M(UMR.java:863)
 at com.objectdb.o.UMR.D(UMR.java:663)
 at com.objectdb.o.ENT.u(ENT.java:325)
 at com.objectdb.o.STA.ae(STA.java:819)
 at com.objectdb.o.STM.I(STM.java:573)
 at com.objectdb.o.OBM.bL(OBM.java:1035)
 at com.objectdb.o.OBM.bG(OBM.java:821)
 at com.objectdb.o.OBM.bE(OBM.java:715)
 at com.objectdb.jpa.EMImpl.commit(EMImpl.java:274)
 ... 1 more
Caused by: java.lang.IllegalArgumentException: Can not set int field image.MetaSogou.iHei to image.Meta
 at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
 at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
 at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
 at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(UnsafeIntegerFieldAccessorImpl.java:38)
 at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(UnsafeIntegerFieldAccessorImpl.java:18)
 at java.lang.reflect.Field.get(Field.java:358)
 at com.objectdb.o.UMR$Q.E(UMR.java:1007)
 at com.objectdb.o.UMR.D(UMR.java:660)
 ... 8 more
Error opening zip file or JAR manifest missing: /E:/projects/objectdb/bin/objectdb.jar

I saw the Meta still has two sets of members, see the attachment!

TIA

Institute of Computer Technologies
#12

The new issue should be posted as a new forum thread with a simple test case and possibly with an existing database that the test case tries to access and fails.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#13

This is a relevant question, that is how Objectdb know the modification of classes. My .odb file is 15GB, I think your have no room to put it into the forum. You can follow the same processing:

>> I ever make a class of Meta. Then I generalize it to MetaSogou, Meta only has additional functions. Now, I restore the Meta to independent.

TIA   

Institute of Computer Technologies
#14

If it is simple to follow and repeat then please try it yourself on a new project with 2 small classes and small database, and provide exact instructions (that have been verified by you first) how to reproduce it.

As already explained to you, it is much easier to build such a test for someone that experience the problem and can reduce his application to a small test. Eventually during this process of isolating the problem you may find that some specific features of your application (e.g. the exact object model) affects. Actually in most cases it is impossible for someone that has not experienced the problem to build a test case and trying to build it from scratch is a waste of time.

Your opinion may be different and I respect it, but please respect the forum rules if you want to use it.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login