surinder-insonix / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

Allow reuse of columns across multiple fields #198

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This test fails:
public class BugsJPA extends JPATestCase {

  @Entity
  public static class Foo {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Basic
    private Key barKey;

    @OneToOne(fetch = FetchType.LAZY)
    @Column(name = "barKey", insertable = false, updatable = false)
    private Bar barAlias;
  }

  @Entity
  public static class Bar {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;
  }

  public void testKeyField() throws EntityNotFoundException {
    beginTxn();
    Foo pojo = new Foo();
    em.persist(pojo);
    commitTxn();
    com.google.appengine.api.datastore.Entity e =
        ldth.ds.get(KeyFactory.createKey("BugsJPA$Foo", pojo.id));
    assertTrue(e.hasProperty("barKey"));
  }
}
The entity gets written with a property named "barKey_0" instead of 
barKey.  Why?

Original issue reported on code.google.com by max.r...@gmail.com on 21 Mar 2010 at 11:50

GoogleCodeExporter commented 8 years ago
Aliases does not work either 

@Entity
public class Foo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;

@Basic
public Key bar;

@OneToOne(fetch = FetchType.LAZY)
@Column(name = "bar", insertable = false, updatable = false)
public Bar barAlias;
}

@Entity
public class Bar {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Key key;
}

public class UnOwnedRelationshipTest extends BaseDataStoreTest {

public void testRelation() throws EntityNotFoundException {

Bar bar = new Bar();
beginTx();
getEntityManager().persist(bar);
commitTx();

beginTx();
Foo pojo = new Foo();
pojo.bar = bar.key;
getEntityManager().persist(pojo);
commitTx();

pojo = getEntityManager().find(Foo.class, pojo.id);
com.google.appengine.api.datastore.Entity e = DatastoreServiceFactory
.getDatastoreService().get(KeyFactory.createKey("Foo", pojo.id));
assertTrue(e.hasProperty("bar"));

//this fails
assertNotNull(pojo.barAlias);

}
}

The test fails, alias is not initialized..
It does not work even when I use getters/setters to access alias, Neither it 
works
for @oneToMany as you explained in example.

I use GAE SDK 1.3.2

See this thread as well
http://groups.google.com/group/google-appengine-java/browse_thread/thread/aefd4e
8b918af4f2

Original comment by sramana...@gmail.com on 1 May 2010 at 10:05

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Why ? apart from the obvious, you have a field called "barKey" which will 
default to column name of "barKey", and then you have a "barAlias" defined to 
use that column, hence when it names the undefined one it suffixes _0.

Obviously if you add @Column to "Key barKey" as
@Column(name="barKey")
Key barKey;

then you end up with
Duplicate column name "barKey" defined for table 
"com.google.appengine.datanucleus.bu
gs.test.Foo". You cannot map multiple fields to the same column. The duplicated 
columns are specified by com.google.appengine.datanucleus.b
ugs.test.Foo.barAlias and com.google.appengine.datanucleus.bugs.test.Foo.barKey.
org.datanucleus.store.mapped.exceptions.DuplicateDatastoreFieldException: 
Duplicate column name "barKey" defined for table "com.google.appe
ngine.datanucleus.bugs.test.Foo". You cannot map multiple fields to the same 
column. The duplicated columns are specified by com.google.app
engine.datanucleus.bugs.test.Foo.barAlias and 
com.google.appengine.datanucleus.bugs.test.Foo.barKey.
        at com.google.appengine.datanucleus.mapping.DatastoreTable.isSuperclassColumn(DatastoreTable.java:308)
        at com.google.appengine.datanucleus.mapping.DatastoreTable.addDatastoreField(DatastoreTable.java:251)
        at com.google.appengine.datanucleus.mapping.DatastoreTable.addDatastoreField(DatastoreTable.java:93)
        at com.google.appengine.datanucleus.mapping.DatastoreMappingManager.createDatastoreField(DatastoreMappingManager.java:155)

So are you expecting the plugin to reuse columns for different fields ? because 
it is not part of the JPA spec.

Original comment by googleco...@yahoo.co.uk on 21 Jul 2011 at 10:28

GoogleCodeExporter commented 8 years ago

Original comment by googleco...@yahoo.co.uk on 10 Aug 2011 at 10:27

GoogleCodeExporter commented 8 years ago
Hello,

When this issue will be solved? 
I really need it.

Best Regards

Original comment by sergeydo...@gmail.com on 19 May 2014 at 9:17