Possible issue with Spring JPA and Embedded

#1

Hello,

I'm having some fun with Spring and embedded objects. I have need to embed some small objects inside another object. When I tried this from our project it doesn't work, so I created a small unit test (which is attached called "TestEmbeddable.java"), and it works perfectly. So I think that the annotations I have used are ok. However it will not work from spring. I'm not certain whether this is due to something spring wants or whether there is an issue with objectdb. I'm not really sure how to go about proving where the issue is. (I can see the embedded objects in the database with the explorer, but they are NEVER returned) If I change my embedded class to be an entity it all works happily.

I have attached a spring maven project (use 'mvn eclipse:eclipse' to generate the maven project, and then 'import' into eclipse). I've stripped out as much as I can, but not sure how I can simplify it any further.

I'm hoping that this is just me not understanding required annotations.

Thanks

Paul.

application/zip iconobjectdb_spring_1.zip (14.5KB)
Spring project that doesn't work
text/x-java iconTestEmbeddable.java (5.69KB)
Simple test that works
#2

The difference between the two tests is that Spring JPA returns detached objects.

A collection of embedded objects is loaded lazily by default so it will not be available after detach.

Your Spring JPA test passes if you set eager fetch for that collection:

    @ElementCollection(fetch=FetchType.EAGER)
    public List<RulePart> getRules() {
        return rules;
    }
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Thanks for the quick response... thats got it!!


Post Reply

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