-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: Problems with annotations in 3.2.0.ga
PostPosted: Sun Oct 22, 2006 7:41 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
I've just migrated from 3.2.0.rc2 to 3.2.0.ga
Everything was working in rc2.
Now i have such exception during initialization.

org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.mypkg.core.dao.hibernate.persistent.OwnedUserStocks.stock in com.mypkg.core.dao.hibernate.persistent.Stock.ownedStocks
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:506)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:471)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1054)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1210)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:807)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:740)


Here's my annotations:
Code:
@Entity
@DiscriminatorValue("owned")
@Proxy(lazy = true, proxyClass = com.mypkg.core.dao.hibernate.persistent.OwnedUserStocks.class)
public class OwnedUserStocks extends UserStocks {
}


Code:
@Entity
@DiscriminatorValue("owed")
@Proxy(lazy = true, proxyClass = com.mypkg.core.dao.hibernate.persistent.OwedUserStocks.class)
public class OwedUserStocks extends UserStocks implements IOwedUserStocks {
  ...
}


Code:
@BatchSize(size = 20)
@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
        name = "stock_type",
        discriminatorType = DiscriminatorType.STRING
)
@DiscriminatorValue("common")
@Table(name = "user_stocks")
public abstract class UserStocks extends AbstractIDComparable implements IUserStocks {
...
...
@ManyToOne(targetEntity = com.mypkg.core.dao.hibernate.persistent.Stock.class,
            cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
    @JoinColumn(name = "stock_id", nullable = false)
    public IStock getStock() {
        return stock;
    }
...
}


Code:
@BatchSize(size = 15)
@Entity
@Table(name = "stock")
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Proxy(lazy = true, proxyClass = com.mypkg.core.dao.hibernate.persistent.Stock.class)
@javax.persistence.SequenceGenerator(
        name = "SEQ_STORE",
        sequenceName = "stock_sequence"
)
public class Stock extends AbstractIDComparable implements IStock {
...

@OneToMany(targetEntity = com.mypkg.core.dao.hibernate.persistent.OwnedUserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    public List<IUserStocks> getOwnedStocks() {
        if (null == ownedStocks) {
            ownedStocks = new ArrayList<IUserStocks>();
        }
        return ownedStocks;
    }

    @OneToMany(targetEntity = com.mypkg.core.dao.hibernate.persistent.OwedUserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    public List<IUserStocks> getOwedStocks() {
        if (null == owedStocks) {
            owedStocks = new ArrayList<IUserStocks>();
        }
        return owedStocks;
    }
}


I use Spring for Hibernate configuration and required classes are in Spring configuration. So hiberante should find all classes. And this configuration was wroking on 3.20.rc2. I've just change hibernate version in pom.xml (maven configuration file) and don't make any other changes.
Is it bug or i should make some changes ?
I look at migration guide and i don't see any issues related to my problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 11:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
if should really be
Code:
@OneToMany(targetEntity = com.mypkg.core.dao.hibernate.persistent.OwnedUserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)

to comply with the definition of the many to one

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 12:14 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
emmanuel wrote:
if should really be
Code:
@OneToMany(targetEntity = com.mypkg.core.dao.hibernate.persistent.OwnedUserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)

to comply with the definition of the many to one


Sorry, what do you mean
because i've got this mapping in Stock class.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 8:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sorry I mean
Code:
@OneToMany(targetEntity = com.mypkg.core.dao.hibernate.persistent.UserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)

to comply with the definition of the many to one[/quote]

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 4:24 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
emmanuel wrote:
Sorry I mean
Code:
@OneToMany(targetEntity = com.mypkg.core.dao.hibernate.persistent.UserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)

to comply with the definition of the many to one
[/quote]

Why do i need this ?
I have abstract class UserStocks and 2 classes which extends it (OwnedStocks and OwedStocks).
In UserStocks i have mapping:

Code:
@ManyToOne(targetEntity = com.mypkg.core.dao.hibernate.persistent.Stock.class,
            cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
    @JoinColumn(name = "stock_id", nullable = false)
    public IStock getStock() {
        return stock;
    }


And in Stock class i don't need collection of abstract UserStocks. I need 2 collections of concrete classes (OwnedStcoks and OwedStocks).
That's why i created in Stock such mappings:

Code:
@OneToMany(targetEntity = com.mypkg.core.dao.hibernate.persistent.OwnedUserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    public List<IUserStocks> getOwnedStocks() {
        return ownedStocks;
    }

    @OneToMany(targetEntity = com.mypkg.core.dao.hibernate.persistent.OwedUserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    public List<IUserStocks> getOwedStocks() {
        return owedStocks;
    }



I don't need 3d collection which returns all objects of UserStocks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 5:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
because conceptually this is not a bidirectional association if one side contains only a subtype of the other side.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 5:41 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
emmanuel wrote:
because conceptually this is not a bidirectional association if one side contains only a subtype of the other side.


I really don't understand where is there an conceptual error.
I have abstract A class which has association to B class, A1 and A2 are its children. And class B has 2 collections of A1 and A2. It's a normal bidirection association.
Could you explain ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 8:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
stock points to a collection of OwnedUserStock
to the opposite side can only be of type OwnedUserStock, otherwise I could persist a Stock object (not a OwnedUserStock) into the manytoone association

Later on the oneToMany would contain a Stock object which is illegal because declared as a collection of OwnedUserStock

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 08, 2006 6:35 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
emmanuel wrote:
stock points to a collection of OwnedUserStock
to the opposite side can only be of type OwnedUserStock, otherwise I could persist a Stock object (not a OwnedUserStock) into the manytoone association

Later on the oneToMany would contain a Stock object which is illegal because declared as a collection of OwnedUserStock

Brrrr....
I have abstract UserStock, and its children Owned and Owed
and i have Stock class.
Stock class has 2 collection for Owned, Owed
So i can't store Stock to its collections only Owned or Owed.
Stock class doesn't implement IUserStocks interface.
Only UserStock implements IUserStocks interface.

I just want to implement such logic:
C class contains 2 collection of A subclasses (A1 and A2) and A class has reference to C class.
How can i do this ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 08, 2006 5:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
darkit wrote:
C class contains 2 collection of A subclasses (A1 and A2) and A class has reference to C class.
How can i do this ?


As I said this is not possible. the A -> C is not the bidirectional version of C -> A1
they do not point to the same concrete class.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 04, 2007 12:41 pm 
Newbie

Joined: Mon Nov 26, 2007 12:49 pm
Posts: 7
emmanuel wrote:
As I said this is not possible. the A -> C is not the bidirectional version of C -> A1
they do not point to the same concrete class.



So do you think it could be fixed by doing this?

Code:
    @OneToMany(targetEntity = OwnedUserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    public List<OwnedUserStocks> getOwnedStocks() {
        return ownedStocks;
    }

    @OneToMany(targetEntity = OwedUserStocks.class, mappedBy = "stock",
            cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    public List<OwedUserStocks> getOwedStocks() {
        return owedStocks;
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.