java - JPA AccessType.Property failing to retrieve value from nested classes -
i'm attempting parse json @entity in order persist data in table. confirmed parsing works have run issue when attempting persist data. in order retrieve needed value in nested classes (two deep) using @access(accesstype.property) annotation on "helper" method.
my best guess entity object being created prior retrieving value nested classes , when attempts retrieve "nested" value class instances null. result unable map value persistence field.
below ascertain important part of exception:
exception description: method [getnestedhref] on object [com.something.dotcom.bleep.parsers.hierarchyv2] triggered exception. internal exception: java.lang.reflect.invocationtargetexception target invocation exception: java.lang.nullpointerexception mapping: org.eclipse.persistence.mappings.directtofieldmapping[nestedhref-->schema.tbl_hierarchy.href] descriptor: relationaldescriptor(com.something.dotcom.bleep.parsers.hierarchyv2 --> [databasetable(schema.tbl_hierarchy)])
below json i'm parsing:
{ "links": { "self": { "href": "http:\/\/data.something.com\/v2\/hierarchy\/blah\/id\/blahblah" } }, "name": "namevalue", "id": "idvalue", "hierarchyid": "hierarchyvalue", "narrowerterm": [ { "href": "http:\/\/data.something.com\/v2\/hierarchy\/blah\/id\/somethingelse1", "sequence": 0 }, { "href": "http:\/\/data.something.com\/v2\/hierarchy\/blah\/id\/somethingelse2", "sequence": 1 }, { "href": "http:\/\/data.something.com\/v2\/hierarchy\/blah\/id\/somethingelse3", "sequence": 2 } ] }
i'm having no issue persisting name, id, hierarchy_id, upd , crt dates. able log href using tostring() method. however, cannot seem persist value (see href in links-->self-->href).
@jsonignoreproperties({"href","parentid","recordcreatedate","recordupdatedate"}) @entity //@cache(isolation = cacheisolationtype.isolated) @table(name = "hierarchy_v2", schema = "schema") @access(accesstype.field) public class hierarchyv2{ @id private string id; private string name; @column(name = "hierarchy_id") private string hierarchyid; @column(name = "parent_id") private string parentid; @temporal(temporaltype.timestamp) @column(name = "rec_crt_dt") private date recordcreatedate; @temporal(temporaltype.timestamp) @column(name = "rec_upd_dt") private date recordupdatedate; @transient private hierarchylinks links; @transient private list<hierarchyterm> broaderterm; @transient private list<hierarchyterm> narrowerterm; //typical getters, setters, overridden methods.... @access(accesstype.property) @column(name = "href") protected string getnestedhref(){ return this.links.getself().gethref(); } protected void setnestedhref(string href){ hierarchylinks links = new hierarchylinks(); this.links = links; hierarchyv2self hvs = new hierarchyv2self(); this.links.setself(hvs); hvs.sethref(href); } @override public string tostring(){ return this.name + "\t" + this.id + "\t" + this.hierarchyid + "\t" + this.getnestedhref() + "\t" + this.parentid; }
following "nested" classes. fooled around @embeddable , @embedded annotations in attempt make work - , without putting thought brain mush. had these classes static inner classes , moved them out of entity class.
i spent 4 hours writing , rewriting , i'm swallowing pride. appreciated.
public class hierarchylinks { private hierarchyv2self self; public hierarchyv2self getself() { return self; } public void setself(hierarchyv2self self) { this.self = self; } } public class hierarchyv2self { private string href; public string gethref() { return href; } public void sethref(string href) { this.href = href; } }
your @transient annotation may causing problem here.
@transient private string href;
@transient used indicate perticular field should not persisted in underlying persistance system i.e. database.
you may follow this link
Comments
Post a Comment