-->
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.  [ 7 posts ] 
Author Message
 Post subject: org.hibernate.MappingException: Unknown entity with derived
PostPosted: Tue Feb 23, 2016 4:02 am 
Newbie

Joined: Tue Feb 23, 2016 3:34 am
Posts: 5
Hello everybody.

I have a number of POJOs auto-generated with the Hibernate reverse engineering feature. They look like:
Code:
package db;
/**
* Pojo generated by hbm2java
*/
public class Pojo implements java.io.Serializable
{
    private int id;

    public Pojo() {
    }

    public Pojo(int id) {
        this.id = id;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }
}


I need to do various things with some of these POJOs and thus created derived classes, such as:
Code:
package input;

public class Pojo extends db.Pojo
{
    public Pojo()
    {
        // TODO Auto-generated constructor stub
        super();
    }

    public void doSomething()
    {}
}


At some point I need to store new instances of these POJOs using a Session object:

Quote:
input.Pojo pj = new input.Pojo();
pj.doSomething();
session.save((db.Pojo) pj);


Even though the POJO instance is being cast to the generated parent class, Hibernate gets upset and spits out the familiar exception:

Quote:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: input.Pojo


Naturally, I could created new methods in the generated POJOs, but I would prefer to leave them unchanged (particularly since the database is expected to evolve). Is it possible to avoid this exception? Say, by "forcing" Hibernate to recognise the cast? Or can this be achieved some other way?

Thank you.


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity with derived
PostPosted: Tue Feb 23, 2016 6:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Hibernate is aware of the db.Pojo class but it doesn't have any mapping for input.Pojo.

You should add the doSomething method into the db.Pojo class.


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity with derived
PostPosted: Wed Feb 24, 2016 4:56 am 
Newbie

Joined: Tue Feb 23, 2016 3:34 am
Posts: 5
mihalcea_vlad wrote:
You should add the doSomething method into the db.Pojo class.


It will get deleted when the POJO is generated.

Cheers.


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity with derived
PostPosted: Wed Feb 24, 2016 5:41 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
For practical reasons, the auto-generated source code shouldn't overwrite the project sources.
Most such generators, us ethe Maven target folder for that like the Metamodel generator.

This way, you can do the merge between the existing entities and the newly generated entity classes manually.


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity with derived
PostPosted: Wed Feb 24, 2016 6:33 am 
Newbie

Joined: Tue Feb 23, 2016 3:34 am
Posts: 5
mihalcea_vlad wrote:
For practical reasons, the auto-generated source code shouldn't overwrite the project sources.


Would there be a bug with the reverse engineering feature? In any event, if there are changes to the model, I would prefer the reverse engineering to reflect them.

mihalcea_vlad wrote:
Most such generators, us ethe Maven target folder for that like the Metamodel generator.


I am not using Maven. Nor is it clear why should the reverse engineering use it...

mihalcea_vlad wrote:
This way, you can do the merge between the existing entities and the newly generated entity classes manually.


I do not understand this so well. The goal of using inheritance is precisely to avoid "manual" changes and replication.

Thank you.


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity with derived
PostPosted: Wed Feb 24, 2016 7:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I was referring to the export part. I'd choose a different target folder than the one used to store the project sources.

Quote:
The goal of using inheritance is precisely to avoid "manual" changes and replication.


Inheritance has its goals, but I don't think that avoiding "manual" changes and database replication are related to it.


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity with derived
PostPosted: Thu Feb 25, 2016 9:23 am 
Newbie

Joined: Tue Feb 23, 2016 3:34 am
Posts: 5
I must confess I am at a loss here.

mihalcea_vlad wrote:
I was referring to the export part. I'd choose a different target folder than the one used to store the project sources.


I have no idea how the export feature comes into play here. As far as I know it is not being used (correct me if I am wrong).

mihalcea_vlad wrote:
Inheritance has its goals, but I don't think that avoiding "manual" changes and database replication are related to it.


There is no replication in the this particular database. That is not the issue here.

Cheers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.