that simply means that value doesn't contain a valid object id.

You may see valid ids  running 
SELECT %ID FROM DATA.Persistent

most likely some integer

check if your value is an existing Id  after the %OpenId

if 'Obj do $system.OBJ.DisplayError()
else  zwrite Obj


so you see what's going on

the method to open is
Set Obj=##Class(Data.Persistent).%OpenId(value)

COS is case sensitive

your example has neither a Property Discharge
nor as Serial object Discharge with a Property DischargeFlag
<INVALID OREF> refers to the missing Property as SerialObject

It seems you try to create properties and substructures similar to JSON.
You have to define everything in advance before you can use it.

To achieve the expected result of individual storage you may take this approach:

Class Test.NewClass Extends %Persistent [ NoExtent ]
{
Property Name As %String [ Required ];
Index NameIndex On Name [ Unique ];
}

and
 

Class Test.NewClass1 Extends Test.NewClass
{
Storage Default
{
<Data name="NewClass1DefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>Name</Value>
</Value>
</Data>
<DataLocation>^Test.NewClass1D</DataLocation>
<DefaultData>NewClass1DefaultData</DefaultData>
<IdLocation>^Test.NewClass1D</IdLocation>
<IndexLocation>^Test.NewClass1I</IndexLocation>
<StreamLocation>^Test.NewClass1S</StreamLocation>
<Type>%Library.CacheStorage</Type>
}

}

and you see:
ERROR #5808: Key not unique: Test.NewClass1:NameIndex:^Test.NewClass1I("NameIndex"," A1")

  • LAST_IDENTITY ()  only refers to %ROWID  and is quite volatile and just a getter for  %ROWID  
  • so you may run this query immediately following your INSERT 

      &SQL( SELECT id into :pid from users where %ID=LAST_IDENTITY()
or simply
       &SQL( SELECT id into :pid from users where %ID=:%ROWID 

set claim=##class(Claim).%OpenId(claimnum)  ; or similar
set line=##class(ClaimLine).%OpenId(linenum) ; or similar
do claim.ClaimLineRel.Insert(line)

now your query should work