Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 844287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:15:43+00:00 2026-05-15T06:15:43+00:00

im new in hibernate and JPA and i have some problems with annotations. My

  • 0

im new in hibernate and JPA and i have some problems with annotations.

My target is to create this table in db (PERSON_TABLE with personal-details)

ID      ADDRESS     NAME    SURNAME     MUNICIPALITY_ID

First of all, i have a MUNICIPALITY table in db containing all municipality of my country.
I mapped this table in this ENTITY:

@Entity
public class Municipality implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String country;
private String province;
private String name;
@Column(name="cod_catasto")
private String codCatastale;
private String cap;


public Municipality() {
}

...

Then i make an EMBEDDABLE class Address containing fields that realize a simple address…

@Embeddable
public class Address implements Serializable {

@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="id_municipality")
private Municipality municipality;
@Column(length=45)
private String address;

public Address() {
}

...

Finally i embedded this class into Person ENTITY

@Entity
public class Person implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String name;
private String surname;
@Embedded
private Address address;

public Person() {
}

...

All works good when i have to save a new Person record, in fact hibernate creates a PERSON_TABLE as i want, but if i try to retrieve a Person record i have an exception.
HQL is simply “from Person”
The excpetion is (Entities is the package containing all classes above-mentioned):

org.hibernate.AnnotationException: @OneToOne or @ManyToOne on Entities.Person.address.municipality references an unknown entity: Entities.Municipality

Is the @OneToOne annotation the problem?

My hibernate.cfg.xml is this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
        <property name="hibernate.connection.driver_class">org.h2.Driver</property>
        <property name="hibernate.connection.url">jdbc:h2:tcp://localhost/DB_PATH</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <mapping class="Entities.Person"/>
        <mapping class="Entities.Municipality"/>
        <mapping class="Entities.Address"/>
    </session-factory>
</hibernate-configuration>

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:15:44+00:00Added an answer on May 15, 2026 at 6:15 am

    The problem is… i lunch my querys into netbeans “HQL Query()” tab, i try to create a query

    session.createQuery("from Person");
    

    and all works good.

    Sorry guys my fault, i do this test first… i thought that HQL wizard into netbeans was a reliable tool to test queries…

    In this case, wich of answer i have to choice? All are reasonable and full of tips!

    Sorry again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to hibernate and have stumbled on this problem, which I can't
I am new to JPA/Hibernate. Currently using EJB3, Hibernate/JPA. I have an inheritacnce structure
I have following Hibernate 3 mapping for User class: <class name=org.test.User table=users> ... some
I have a question concerning Hibernate 3.6.7 and JPA 2.0. Consider following entities (some
I am trying to create a new Java EE project using hibernate and JPA
Hi i am new to hibernate technology and i have few issues. Suppose if
I am new to Hibernate. I have an exception while running an Hibernate-based application.
I am new to hibernate and I am stumped. In my database I have
I'm new to Hibernate and I'm struggling with problem: I have 3 tables and
I have a Spring/JPA/Groovy/Hibernate stack, (note: not grails ), and I'm finding that I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.