openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Håkon Sagehaug" <Hakon.Sageh...@bccs.uib.no>
Subject Re: Using object as a type for a filed in a enity
Date Thu, 13 Nov 2008 08:18:05 GMT
Hi

The example is not from the OpenJPA documentation, but self made. Here is
how it looks. My entity looks like this

@Entity
@Table(name = "objecttable2")
public class ObjectHolder implements Serializable {

    private Object theObject;
    @Id
    @GeneratedValue()
    private int id;
    private static final long serialVersionUID = 1L;


// getters and setters

public void setTheObject(Object theObject) {
    this.theObject = theObject;
    }

}

my table in postgres is defined like this

CREATE TABLE objecttable
(
  "object" bytea,
  id integer NOT NULL,
  CONSTRAINT objecttable_pkey PRIMARY KEY (id)
)

and in  my main program I do like this
ObjectHolder o = new ObjectHolder();
    ObjectHolderDAO dao = new ObjectholderDAOImpl(em);

java.util.List<Integer> list = new ArrayList<Integer>();
    list.add(new Integer(5));

    o.setTheObject(list);

dao.save(o);

But then when I want to collect it like this

ObjectHolder in = dao.find(new Integer(572));

I get null if I do like this

in.getTheObject();

does this help to figure out my problem?

Håkon

2008/11/13 Craig L Russell <Craig.Russell@sun.com>

> Hi Håkon,
>
> On Nov 12, 2008, at 5:16 AM, Håkon Sagehaug wrote:
>
>  Hi
>>
>> Would it be better to have the field as a byte[], then write the object to
>> this array and the store it, instead of straight from Object to db
>>
>
> That's exactly what OpenJPA is doing, so there's no reason why you should
> have to do it manually.
>
> Just a bit of debugging is needed to see why OpenJPA isn't properly storing
> or retrieving your object.
>
> Were you following an example from OpenJPA documentation, or trying some
> things that sounded right?
>
> Craig
>
>
>>
>> Håkon
>>
>> 2008/11/12 Håkon Sagehaug <Hakon.Sagehaug@bccs.uib.no>
>>
>>  hi
>>>
>>> So now I got a class that has a field that is of type java.lang.Object, I
>>> seems to go fine storing it, but when I want to retrieve the object from
>>> the
>>> db I get null.
>>>
>>> I use postgresql and tried with two tables one with datatype oid and one
>>> with bytea, but both returns null.
>>>
>>> Is this the right approach or is this wrong.
>>>
>>> any tips
>>>
>>> cheers, Håkon
>>>
>>> 2008/11/12 Håkon Sagehaug <Hakon.Sagehaug@bccs.uib.no>
>>>
>>> Hi
>>>
>>>>
>>>> So what I got out of this is, if I've got a object asd type for a field
>>>> I
>>>> can persist it but not query it for content, right?? That's fine for me.
>>>>
>>>> cheers, Håkon
>>>>
>>>>
>>>> 2008/11/11 Pinaki Poddar <ppoddar@apache.org>
>>>>
>>>>
>>>>  Hi,
>>>>> Please refer [1] for different levels of support OpenJPA provides for
>>>>> relation fields whose types are not explicitly declared at design time.
>>>>>
>>>>> [1]
>>>>> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#type
>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>>
>>>>> http://n2.nabble.com/Using-object-as-a-type-for-a-filed-in-a-enity-tp1485319p1485602.html
>>>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>>
>>>>
>>>> --
>>>> Håkon Sagehaug, Software Developer
>>>> Parallab, Bergen Center for Computational Science (BCCS)
>>>> UNIFOB AS (University of Bergen Research Company)
>>>>
>>>>
>>>
>>>
>>> --
>>> Håkon Sagehaug, Software Developer
>>> Parallab, Bergen Center for Computational Science (BCCS)
>>> UNIFOB AS (University of Bergen Research Company)
>>>
>>>
>>
>>
>> --
>> Håkon Sagehaug, Software Developer
>> Parallab, Bergen Center for Computational Science (BCCS)
>> UNIFOB AS (University of Bergen Research Company)
>>
>
> Craig L Russell
> Architect, Sun Java Enterprise System http://db.apache.org/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
>


-- 
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message