@Transient

#1

Hello,

I have a persistent class which looks something like this:

@Entity
public class Test {
    private String string;
    private Date date;

    @Transient
    private boolean test;
    
    // getters/setters
}

When I persist the class the transient 'boolean test' is stored in the database, maybe I am doing it wrong but I expect

the 'boolean test' is not stored in the database because it's a (annotated) transient field?

Regards,

Will

#2

This is strange. I just checked with a simple test program and the @Transient field was not stored in the database.

Why do you think it is stored in the database?

Could you please provided a simple test case that demonstrates the problem?

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

I just ran my test again, the database is created from scratch, and then when I open the database in the explorer I see

the ´boolean searched´ attribute in the object browser. See attached screenshot.

I did not expect to see the searched attribute in the explorer´s object browser since it´s annotated as transient?

This is part of the code that persists the Agency class: 

public Agency saveAgency(Agency agency) { 

    odb.getTransaction().begin();
    odb.persist(agency);
    odb.getTransaction().commit();

    return agency;
}

I also attached the source for the Agency class maybe you can see what I am doing wrong?

 

text/x-java iconAgency.java (3.76KB)
my persistence class
image/jpeg iconexplorer-screenshot.jpg (287KB)
screenshot of explorer after persistence class is stored
#4

The Explorer displays transient fields but their values are not stored in the database, so only default values are presented (e.g. false in your searched field). Try to store a true value and see that the Explorer still shows false value.

The Explorer knows that a searched field exists because transient fields are stored as part of the class schema in the database (but only as part of the schema, values of these fields are not stored in the database).

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

Thanks that explains it although I must say it is a bit confusing seeing a transient field in the explorer.

Maybe you could filter transient fields so they are not visible.

I have another question:

How does ObjectDB handle changes in persistance classes, e.g. adding/renaming/deleting fields?

#6

You are right. It might be confusing and it would be better to filter transient fields from object display.

Handling schema changes is explained at:

http://www.objectdb.com/java/jpa/entity/schema

http://www.objectdb.com/java/jpa/setting/schema

If you have further questions about schema changes please open a new thread since it is a different topic than the original post.

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

So to be clear... columns are created for transient fields, but the values of those fields are not stored?

I guess it doesn't matter, as long as it works.  I don't have any entity classes with large numbers of transient fields uselessly taking up space in the tables.

#8

ObjectDB is not an RDBMS so there are no tables and columns, but you are right - transient fields consume space in the database only for their definition (several bytes) but not for their values.

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

Post Reply

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