OpenPojo / openpojo

POJO Testing & Identity Management Made Trivial
http://openpojo.com
Apache License 2.0
156 stars 40 forks source link

stackoverflow businesskey on foreign keys #39

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. have a parent child relation
2. add businesskey on foreign key and another
3. equals and hashcode using BusinessIdentity

What is the expected output? What do you see instead?
java.lang.StackOverflowError
    at java.util.regex.Pattern$5.isSatisfiedBy(Pattern.java:5151)
    at java.util.regex.Pattern$CharProperty.match(Pattern.java:3694)
    at java.util.regex.Pattern$GroupHead.match(Pattern.java:4556)
    at java.util.regex.Pattern$Branch.match(Pattern.java:4500)
    at java.util.regex.Pattern$Branch.match(Pattern.java:4500)
    at java.util.regex.Pattern$Branch.match(Pattern.java:4500)
    at java.util.regex.Pattern$BranchConn.match(Pattern.java:4466)
    at java.util.regex.Pattern$GroupTail.match(Pattern.java:4615)
    at java.util.regex.Pattern$Curly.match0(Pattern.java:4177)
    at java.util.regex.Pattern$Curly.match(Pattern.java:4132)
    at java.util.regex.Pattern$GroupHead.match(Pattern.java:4556)
    at java.util.regex.Pattern$Branch.match(Pattern.java:4502)
    at java.util.regex.Pattern$Branch.match(Pattern.java:4500)
    at java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3715)
    at java.util.regex.Pattern$Start.match(Pattern.java:3408)
    at java.util.regex.Matcher.search(Matcher.java:1199)
    at java.util.regex.Matcher.find(Matcher.java:618)
    at java.util.Formatter.parse(Formatter.java:2517)
    at java.util.Formatter.format(Formatter.java:2469)
    at java.util.Formatter.format(Formatter.java:2423)
    at java.lang.String.format(String.java:2797)
    at com.openpojo.reflection.utils.ToStringHelper.nameValuePair(ToStringHelper.java:44)
    at com.openpojo.reflection.impl.PojoFieldImpl.toString(PojoFieldImpl.java:175)
    at com.openpojo.reflection.utils.ToStringHelper.PojoFieldsToString(ToStringHelper.java:76)
    at com.openpojo.reflection.utils.ToStringHelper.pojoClassToString(ToStringHelper.java:58)
    at com.openpojo.reflection.impl.PojoClassImpl.toString(PojoClassImpl.java:139)
    at com.openpojo.business.BusinessIdentity.toString(BusinessIdentity.java:77)
    at no.datametrix.smartguestjpa.entity.TSgRadcheckAttributes.toString(TSgRadcheckAttributes.java:191)
    at java.lang.String.valueOf(String.java:2854)
    at java.lang.StringBuilder.append(StringBuilder.java:128)
    at org.eclipse.persistence.internal.identitymaps.CacheKey.toString(CacheKey.java:512)
    at java.util.Formatter$FormatSpecifier.printString(Formatter.java:2838)
    at java.util.Formatter$FormatSpecifier.print(Formatter.java:2718)
    at java.util.Formatter.format(Formatter.java:2488)
    at java.util.Formatter.format(Formatter.java:2423)
    at java.lang.String.format(String.java:2797)
    at com.openpojo.reflection.utils.ToStringHelper.nameValuePair(ToStringHelper.java:44)

What version of the product are you using? On what operating system?
Latest
apache tomee 1.6.0-SNAPSHOT
Ubuntu 12.04

Please provide any additional information below.
using eclipselink 2.5.0

Original issue reported on code.google.com by helge.wa...@gmail.com on 16 Sep 2013 at 8:35

GoogleCodeExporter commented 9 years ago

Are the parent and the child instances pointing to the same instance?
Like this:
Class A {
  @BusinessKey
  private A parent;
}

And in Runtime you're doing:
A instance = new A();
instance.parent = instance;
instance.toString();

-- This would clearly create an infinite recursion as the Identity of 
'instance' is dependent on evaluating 'instance'.

If the example above isn't what is going on, can you please attach a code 
sample for the issue you're facing?

Thank you.

Original comment by oshou...@gmail.com on 22 Sep 2013 at 6:28

GoogleCodeExporter commented 9 years ago
Hi,
I belive this is not the case. I'll see if I can reproduce this error in a demo 
project. However, this is the structure:

Class A:
    @BusinessKey
    @JoinColumn(name = "attribute", referencedColumnName = "attribute_name")
    @ManyToOne(optional = false)
    private B attribute;
    @BusinessKey
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private C userId;
    @BusinessKey
    @JoinColumn(name = "service", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private D service;

Class B:
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "attribute")
    private Collection<A> ACollection;

Class C:
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId", orphanRemoval = true)
    private Collection<A> ACollection;

Class D:
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "service", orphanRemoval = true)
    private Collection<A> ACollection;

best regards,
hw

Original comment by helge.wa...@gmail.com on 29 Sep 2013 at 9:10

GoogleCodeExporter commented 9 years ago
If Class A holds an entry to Class B, and Class B has Collection of Class A, 
doesn't that create a cyclic infinite reference?

Can you please include the equals implementation for A, B, C and D?
I don't see BusinessKey in the B, C or D classes.

Original comment by oshou...@gmail.com on 9 Oct 2013 at 3:39

GoogleCodeExporter commented 9 years ago
Helge,
I haven't heard back from you with regards to this issue.
I am closing this issue as invalid for now, please feel free to comment or 
include a sample to demonstrate the issue, if so, I'll re-open it.

Thank you for your continued interest in OpenPojo.

Original comment by oshou...@gmail.com on 14 Mar 2014 at 8:49