Object equality

2 views
Skip to first unread message

Anna Lu

unread,
Jul 8, 2010, 10:38:13 AM7/8/10
to jenabe...@googlegroups.com
The code is like this

Genre genreAct = new Genre("Action", "Action");
Genre genreSci = new Genre("Science fiction", "Science fiction");
Genre genreAdv = new Genre("Adventure", "Adventure");

//if I don't save genres, I cannot load them in the following step. Aren't they stored automatically when they are created?
genreAct.save();
genreSci.save();
genreAdv.save();

Movie movie = createMovie("movie3"); //"movie3" is the Id

movie.getGenres().add(genreAct);
movie.getGenres().add(genreSci);
movie.getGenres().add(genreAdv);

Genre g1 = new Genre().load("Action");
Genre g2 = new Genre().load("Science fiction");
Genre g3 = new Genre().load("Adventure");

Collection<Genre> aGenres = movie.getGenres();
for (Genre aGenre: aGenres){
           if (aGenre.equals(g1))
                System.out.println("Action!");
            else if (aGenre.equals(g2))
                System.out.println("Science!");
            else if (aGenre.equals(g3))
                System.out.println("Adventure!");
 }

The output should be
Action!
Science!
Adventure!

But only "Adventure!" was printed out. Do you have any idea? Thanks for your help in advance.

uoccou

unread,
Jul 8, 2010, 1:40:31 PM7/8/10
to jenabe...@googlegroups.com, Anna Lu
What is your ID field - when you create the 3 genres are they overwriting each other ?
If you add a check to the end of your loop, for genres that match nothing, do you get any extra output ?

Beans have to be save to your model, otherwise they just exist in the JVM. Doing a load() wont locate them from the model.
--
You received this message because you are subscribed to the Google Groups "jenabean-dev" group.
To post to this group, send email to jenabe...@googlegroups.com.
To unsubscribe from this group, send email to jenabean-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jenabean-dev?hl=en.

Taylor Cowan

unread,
Jul 8, 2010, 1:53:47 PM7/8/10
to jenabe...@googlegroups.com
No, they are not saved automatically unless you are using the jpa wrapper...ill give a longer answer once im online

Sent from my HTC



From: Anna Lu <lyc....@gmail.com>
Sent: 08 July 2010 9:38 AM
To: jenabe...@googlegroups.com
Subject: Object equality


The code is like this

Genre genreAct = new Genre("Action", "Action");
Genre genreSci = new Genre("Science fiction", "Science fiction");
Genre genreAdv = new Genre("Adventure", "Adventure");

//if I don't save genres, I cannot load them in the following step. Aren't they stored automatically when they are created?
genreAct.save();
genreSci.save();
genreAdv.save();

Movie movie = createMovie("movie3"); //"movie3" is the Id

movie.getGenres().add(genreAct);
movie.getGenres().add(genreSci);


[The entire original message is not included]

Anna Lu

unread,
Jul 9, 2010, 3:49:41 AM7/9/10
to ultano...@gmail.com, jenabe...@googlegroups.com
1. The ID field is defined like
     @Id
    private String Id;
   
    public Genre(String Id, String Name) {
        super();
        this.Name = Name;
        setId(Id);
    }
   
    With differenct Id, I don't think they overwritten each other.

2. There is no extra ouput.

3. I don't understand. If load() couldn't locate them, there should be NotFoundException but there wasn't.

Anna Lu

unread,
Jul 9, 2010, 3:54:27 AM7/9/10
to jenabe...@googlegroups.com
Hi Taylor,

I don't have much knowledge about JPA but we are using Jena SDB.


--

uoc

unread,
Jul 9, 2010, 4:14:06 AM7/9/10
to jenabe...@googlegroups.com, Anna Lu
what is your movie class like ? what does createMovie() do ?

Anna Lu

unread,
Jul 9, 2010, 4:21:13 AM7/9/10
to uoc, jenabe...@googlegroups.com
public Movie createMovie(String id) {
        Movie movie = new Movie();   
        movie.setId(id);    
        movie.save();
        return movie;
 }

The @id field is the same as Genre,
@Id
private String Id;

uoc

unread,
Jul 9, 2010, 5:54:29 AM7/9/10
to Anna Lu, jenabe...@googlegroups.com
Have your overriden Object.equals and hashcode method on genre ? If not
what is happening during your call to equals() in the loop ?

On 09/07/2010 09:21, Anna Lu wrote:
> public Movie createMovie(String id) {
> Movie movie = new Movie();
> movie.setId(id);
> movie.save();
> return movie;
> }
>
> The @id field is the same as Genre,
> @Id
> private String Id;
>
> On Fri, Jul 9, 2010 at 10:14 AM, uoc<uoc...@gmail.com> wrote:
>
>
>> what is your movie class like ? what does createMovie() do ?
>>
>>
>> On 09/07/2010 08:54, Anna Lu wrote:
>>
>> Hi Taylor,
>>
>> I don't have much knowledge about JPA but we are using Jena SDB.
>>
>>
>> On Thu, Jul 8, 2010 at 7:53 PM, Taylor Cowan<thewebs...@gmail.com>wrote:
>>
>>
>>> No, they are not saved automatically unless you are using the jpa
>>> wrapper...ill give a longer answer once im online
>>>
>>> Sent from my HTC
>>>

>>> ------------------------------


>>> From: Anna Lu<lyc....@gmail.com>
>>> Sent: 08 July 2010 9:38 AM
>>> To: jenabe...@googlegroups.com
>>> Subject: Object equality
>>>
>>>
>>> The code is like this
>>>
>>> Genre genreAct = new Genre("Action", "Action");
>>> Genre genreSci = new Genre("Science fiction", "Science fiction");
>>> Genre genreAdv = new Genre("Adventure", "Adventure");
>>>
>>> //if I don't save genres, I cannot load them in the following step. Aren't
>>> they stored automatically when they are created?
>>> genreAct.save();
>>> genreSci.save();
>>> genreAdv.save();
>>>
>>> Movie movie = createMovie("movie3"); //"movie3" is the Id
>>>
>>> movie.getGenres().add(genreAct);
>>> movie.getGenres().add(genreSci);
>>>
>>>
>>> [The entire original message is not included]
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "jenabean-dev" group.
>>> To post to this group, send email to jenabe...@googlegroups.com.
>>> To unsubscribe from this group, send email to

>>> jenabean-dev...@googlegroups.com<jenabean-dev%2Bunsu...@googlegroups.com>


>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/jenabean-dev?hl=en.
>>>
>>>
>> --

>> You receiDelivered-To: uoc...@gmail.com
>>
> Received: by 10.103.182.11 with SMTP id j11cs174501mup;
> Thu, 8 Jul 2010 09:43:44 -0700 (PDT)
> Return-Path:<jenabean-dev+bncCOGar...@googlegroups.com>
> Received-SPF: pass (google.com: domain of jenabean-dev+bncCOGar...@googlegroups.com designates 10.101.131.36 as permitted sender) client-ip=10.101.131.36;
> Authentication-Results: mr.google.com; spf=pass (google.com: domain of jenabean-dev+bncCOGar...@googlegroups.com designates 10.101.131.36 as permitted sender) smtp.mail=jenabean-dev+bncCOGar...@googlegroups.com; dkim=pass header.i=jenabean-dev+bncCOGar...@googlegroups.com
> Received: from mr.google.com ([10.101.131.36])
> by 10.101.131.36 with SMTP id i36mr365857ann.16.1278607424102 (num_hops = 1);
> Thu, 08 Jul 2010 09:43:44 -0700 (PDT)
> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
> d=googlegroups.com; s=beta;
> h=domainkey-signature:received:x-beenthere:received:received:received
> :received:received-spf:received:received:received:message-id
> :mime-version:from:subject:date:importance:x-priority:to
> :x-original-sender:x-original-authentication-results:reply-to
> :precedence:mailing-list:list-id:list-post:list-help:list-archive
> :sender:list-unsubscribe:content-class:content-type;
> bh=nHrrYsk7Daq0P8rKR36iKB4wS8Sxu3wjCnNdgI49oT0=;
> b=zFh4IPk7u8+LoTFlWlNgKKoJH1HCJVYzW3qW3BPiWtj1VLWk897aLMXy3608pw0Z7p
> fEEu9/19ddo+yedkZgZ7OJ6aZBhi1DEQdRfX4RSLl6su9K7v5GQFRqvWEp65QaY8/zSH
> jFJjU7+DYGbvnQsRX4Li3S0k4hc7HHwUgJ6SU=
> DomainKey-Signature: a=rsa-sha1; c=nofws;
> d=googlegroups.com; s=beta;
> h=x-beenthere:received-spf:message-id:mime-version:from:subject:date
> :importance:x-priority:to:x-original-sender
> :x-original-authentication-results:reply-to:precedence:mailing-list
> :list-id:list-post:list-help:list-archive:sender:list-unsubscribe
> :content-class:content-type;
> b=jOwTWVvQnipqURbVpz3M5jmoAg3X4gZ/BOcbUWK3LClsG6dOcWMIHvxF+pfV9fQgBQ
> Rb6mKdouYEyX/RP6XH+edsonhD9NAvrpu3F6mVABCIJIgtAsQd4APOtc6M4PTWPRz5JV
> O3n7iP0nvg1tub9aKgClNte4JpVLWBCYx3BcI=
> Received: by 10.101.131.36 with SMTP id i36mr73000ann.16.1278607423829;
> Thu, 08 Jul 2010 09:43:43 -0700 (PDT)
> X-BeenThere: jenabe...@googlegroups.com
> Received: by 10.101.200.2 with SMTP id c2ls8739265anq.4.p; Thu, 08 Jul 2010
> 09:43:43 -0700 (PDT)
> Received: by 10.101.131.14 with SMTP id i14mr6652407ann.16.1278607423591;
> Thu, 08 Jul 2010 09:43:43 -0700 (PDT)
> Received: by 10.101.131.14 with SMTP id i14mr6652405ann.16.1278607423529;
> Thu, 08 Jul 2010 09:43:43 -0700 (PDT)
> Received: from mail-gx0-f169.google.com (mail-gx0-f169.google.com [209.85.161.169])
> by gmr-mx.google.com with ESMTP id j8si6281451ana.5.2010.07.08.09.43.42;
> Thu, 08 Jul 2010 09:43:42 -0700 (PDT)
> Received-SPF: pass (google.com: domain of thewebs...@gmail.com designates 209.85.161.169 as permitted sender) client-ip=209.85.161.169;
> Received: by gxk4 with SMTP id 4so638489gxk.14
> for<jenabe...@googlegroups.com>; Thu, 08 Jul 2010 09:43:42 -0700 (PDT)
> Received: by 10.150.146.9 with SMTP id t9mr686087ybd.41.1278607422321;
> Thu, 08 Jul 2010 09:43:42 -0700 (PDT)
> Received: from Inbox ([166.188.43.236])
> by mx.google.com with ESMTPS id h11sm2408135ybk.17.2010.07.08.09.43.39
> (version=SSLv3 cipher=RC4-MD5);
> Thu, 08 Jul 2010 09:43:41 -0700 (PDT)
> Message-ID:<4c36003d.0b37...@mx.google.com>
> MIME-Version: 1.0
> From: Taylor Cowan<thewebs...@gmail.com>
> Subject: RE: NotBound Exception ... exists but is not bound to or able to
> coerce as class
> Date: Thu, 8 Jul 2010 11:43:44 -0500
> Importance: normal
> X-Priority: 3
> To:<jenabe...@googlegroups.com>
> X-Original-Sender: thewebs...@gmail.com
> X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com:
> domain of thewebs...@gmail.com designates 209.85.161.169 as permitted
> sender) smtp.mail=thewebs...@gmail.com; dkim=pass (test mode)
> header.i=@gmail.com
> Reply-To: jenabe...@googlegroups.com
> Precedence: list
> Mailing-list: list jenabe...@googlegroups.com; contact jenabean-...@googlegroups.com
> List-ID:<jenabean-dev.googlegroups.com>
> List-Post:<http://groups.google.com/group/jenabean-dev/post?hl=en_US>,
> <mailto:jenabe...@googlegroups.com>
> List-Help:<http://groups.google.com/support/?hl=en_US>,<mailto:jenabean...@googlegroups.com>
> List-Archive:<http://groups.google.com/group/jenabean-dev?hl=en_US>
> Sender: jenabe...@googlegroups.com
> List-Unsubscribe:<http://groups.google.com/group/jenabean-dev/subscribe?hl=en_US>,
> <mailto:jenabean-dev...@googlegroups.com>
> content-class:
> Content-Type: text/plain; charset=ISO-8859-1
>
> When working with existing rdf you need 2 help jb bind. You can do this in several ways, see bind() method on RDF2bean
>
> Sent from my HTC
>
> -----Original Message-----
> From: Arthur<arthur...@gmail.com>
> Sent: 08 July 2010 9:25 AM
> To: jenabean-dev<jenabe...@googlegroups.com>
> Subject: NotBound Exception ... exists but is not bound to or able to coerce as class
>
> I am using JenaBeans to access an existing owl model containing an
> instance (of Well) that imports a schema model (containing the Well
> class). I open the instance model, but when I use the RDF2Bean reader
> to load Well instances, it throws an exception. It is finding the
> correct instance (of Well), but it says that it cannot bind or coerce
> to the class (Well). I am sure this is just a configuration issue.
> Any ideas?
>
> Exception in thread "main" thewebsemantic.NotBoundException:
> http://www.objectreservoir.com/owl/2010/04/14/BP/SampleWell#SampleWell
> exists but is not bound to or able to coerce as class
> com.or.orka.jena_reference.Well
> at thewebsemantic.RDF2Bean.javaclass(RDF2Bean.java:528)
> at thewebsemantic.RDF2Bean.newInstance(RDF2Bean.java:496)
> at thewebsemantic.RDF2Bean.applyProperties(RDF2Bean.java:436)
> at thewebsemantic.RDF2Bean.testCycle(RDF2Bean.java:397)
> at thewebsemantic.RDF2Bean.toObject(RDF2Bean.java:393)
> at thewebsemantic.RDF2Bean.loadIndividuals(RDF2Bean.java:178)
> at thewebsemantic.RDF2Bean.loadAll(RDF2Bean.java:172)
> at thewebsemantic.RDF2Bean.load(RDF2Bean.java:156)
> at thewebsemantic.RDF2Bean.load(RDF2Bean.java:123)
> at
> com.or.orka.jena_reference.WorkspaceManager.main(WorkspaceManager.java:
> 55)
>
> Here is the Well Class. I am not mapping to all the properties of
> Well as this is a feasibility test and well has about 30 properties.
> Could that be the issue?
>
> @Namespace("http://www.objectreservoir.com/owl/2010/02/22/well#")
> public class Well {
>
> String name;
> String API;
> @Id
> URI uri;
>
> public Well(URI uri) {
> this.uri = uri;
> }
>
> public String getAPI() {
> return API;
> }
>
> public void setAPI(String API) {
> this.API = API;
> }
>
> public String getName() {
> return name;
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> public URI getUri() {
> return uri;
> }
>
> public v

Anna Lu

unread,
Jul 9, 2010, 6:49:31 AM7/9/10
to uoc, jenabe...@googlegroups.com
Aha! I know what it is now. You are right. I should overrid Object.equals and hashcode to match genres with Id. Genre A equals genre B if their Ids are the same, right?

uoc

unread,
Jul 9, 2010, 8:48:10 AM7/9/10
to Anna Lu, jenabe...@googlegroups.com
according to RDF, if IDs are same, yes
Reply all
Reply to author
Forward
0 new messages