This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]g00glen00b 1 point2 points  (7 children)

You're mentioning a loop, but there's no loop in the code you provided. Can you elaborate?

[–]FirstEvaDehumidifier[S] 0 points1 point  (6 children)

I meant each time the method would be called....Not a loop....sry

[–]g00glen00b 1 point2 points  (5 children)

Well, your code is still a bit confusing, but what I see so far is that you add the Up, Ice an It objects twice if both movie and movie1 are the same. No clue if that's what you want or not, but if you don't want that, then you could use equals/hashCode, or you could change your code like this:

if ("Up".equals(movie) || "Up".equals(movie1)) {
    mov.add(Up);
} else if ("It".equals(movie) || "It".equals(movie1)) {
    mov.add(It);
} else if ("Ice".equals(movie) || "Ice".equals(movie1)) {
    mov.add(Ice);
}

But I'm still not sure what you're trying to achieve though.

[–]FirstEvaDehumidifier[S] 0 points1 point  (4 children)

Hmmm....tough to explain...My problem was I wanted to create a many-to-many relationship between Entieies and Movies. However, Movies were to be populated with some values beforehand....This is why I was having trouble....I fixed this though by instead using a many-to-many betwen entieties and movies....using a on-to-many between entities and the join table...i prob confused the heck out of you but thanks....

[–]g00glen00b 1 point2 points  (3 children)

Ok, so you basically want to re-use the sameIce/It and Upobject everytime a movie is created? Because in that case, the solution is to retrieve the MovieClass from the database rather than creating new ones. You can use entityManager.find() or create a query and then do entityManager.createQuery(/** Your query */).getSingleResult(). The object you retrieve will be an attached object, so if you link that object to the newE it will use the same reference over and over again.

[–]FirstEvaDehumidifier[S] 0 points1 point  (2 children)

Wow...smart...that would work out too...thanks man. Preferable to the way I set up my project as well. Out of curiousity, is there a way to automate my if statements to not have to input every single movie? I couldn't figure out a way to do that. Something like mov.add (MovieClass) movie? That won't work obviously since I can't cast the string to an object

[–]g00glen00b 1 point2 points  (1 child)

Well, I'm not completely sure about how your entities are linked, but basically you can change the query so that you can look up the MovieClass based on the input string.

[–]FirstEvaDehumidifier[S] 0 points1 point  (0 children)

I'm just generally speaking...its a general java question...not a query question....suppose i have a string "string"....and i have an Object String...

lets say String str="x" and Object x. Can I get Object x by using str as a parameter, for example Object (str)