Perfect. That worked—thanks for the help! I’ve made some pretty good progress—you can save entities and some associations, and retrieve some properties lazily. Unfortunately, I’m having a bit of trouble with getting access to all of the type information I need.
In particular, say you have the hierarchy: @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) (1) @Entity @Table(name = “persistable”) Public class Persistable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; @Basic String persistableName; } @Entity @Table(“person_table”) Public class Person extends Persistable { @Basic @Column(name = “first_name”) String firstName; @Basic @Column String lastName; } I need to generate the schema: :persistable/persistableName :Person/first_name :Person/lastName And access it from a few contexts. Schema Definition When generating the schema, I need to be able to get the table name, which I was able to from the EntityPersisters available in SessionFactoryImpl. From there, I needed to be able to get each property on each class, its type, and its alias (as defined by @Column), which I couldn’t figure out how to do. I looked through both the EntityMetamodel and the ClassMetamodels on each persister, but it wasn’t clear how to get that. Looking in the ClassMetadata, I found the property names, but that included all of the properties for all of the linear supertypes of the associated entity. Looking at the EntityMetamodel, I found I could get all of the properties, but I couldn’t figure out how to filter out the properties declared in the current entity type. I ended up scanning the annotations again to get the information I needed to generate the schema, which doesn’t seem like a good solution. Now, I’m running into the same problem retrieving a tuple: public Tuple getTuple(EntityKey k, TupleContext c) { final Long id = getOrThrowUnexpectedId(k); final Entity entity = retrieveEntity(id); return new Tuple(new LazyEntityBackedTupleSnapshot(entity, tupleContext)); } public class LazyEntityBackedTupleSnapshot implements TupleSnapshot { final Entity entity; final TupleContext context; //constructor, etc. public Object get(String column) { return entity.get(column); } } Now, the problem is, say the entity that I retrieved was a Person. If I call p.getPersistableName() , then entity.get(column) needs to be Entity.get(“:persistable/persistableName”) to get the value. I could search through the linear supertypes of the current type if I could get it. I notice that the actual TupleContext that I’m getting has an OptionsContextImpl with an entity type that I can use to search for the appropriate entity type, but that’s private, and I don’t want to use reflection to get it. I’m sure I’m just missing some cool feature of OGM here, and couldn’t find it looking through the other implementations. Any additional help would be fantastic. Thanks! From: gunnar.morl...@googlemail.com [mailto:gunnar.morl...@googlemail.com] On Behalf Of Gunnar Morling Sent: Wednesday, February 11, 2015 12:43 AM To: Haswell, Josiah D Cc: hibernate-dev@lists.jboss.org Subject: Re: [hibernate-dev] Question about substituting IDs in Hibernate OGM Hi Josiah, It's great to hear that you are working an a backend for Hibernate OGM! Regarding ids, it should work for you if they are mapped using the IDENTITY strategy: @Id @GeneratedValue(strategy=GenerationType.IDENTITY) Long id; This causes the Hibernate ORM engine to read back the id value generated by the datastore upon insertion. To make it work, your GridDialect for OGM needs to implement the IdentityColumnAwareGridDialect facet [1]. You can check out the MongoDB dialect for an example. If this works and this kind of id generation is the only one which is useful for Datomic (i.e. table/sequence strategies don't make any sense), you may validate mapped entities by means of a SchemaDefiner [2] (an experimental contract of OGM). An example is CouchDBSchemaDefiner. Let us know how it goes or in case you run into any other issues. --Gunnar [1] https://github.com/hibernate/hibernate-ogm/blob/master/core/src/main/java/org/hibernate/ogm/dialect/identity/spi/IdentityColumnAwareGridDialect.java [2] https://github.com/hibernate/hibernate-ogm/blob/master/couchdb/src/main/java/org/hibernate/ogm/datastore/couchdb/impl/CouchDBSchemaSchemaDefiner.java 2015-02-11 2:40 GMT+01:00 Haswell, Josiah D <josiah.hasw...@ca.com<mailto:josiah.hasw...@ca.com>>: Hi folks, I'm creating a Hibernate OGM implementation for Datomic, and I have a question about IDs. Say I have the entity @Entity public class Person { @Id @GeneratedValue Long id; } In Datomic, you have to assign a temporary ID before submitting the transaction. Datomic will then return the actual persistence ID after the transaction has completed. My question is, how can I get the actual ID back into the entity? Thanks! Josiah _______________________________________________ hibernate-dev mailing list hibernate-dev@lists.jboss.org<mailto:hibernate-dev@lists.jboss.org> https://lists.jboss.org/mailman/listinfo/hibernate-dev _______________________________________________ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev