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 6000437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:41:36+00:00 2026-05-23T00:41:36+00:00

I have two classes which need to be XML mapped (eventually they will all

  • 0

I have two classes which need to be XML mapped (eventually they will all be modified to Annotations, but currently we need to support the XML mappings).

I have a User object which currently looks like this:

public class User {
    private Key key;
    private Name name;
}

I need to add in Preferences for some of these users (we have two different types of users which share the same object).

public class Preferences {
   private Person person; //The person key acts as our foreign and primary key
   private Integer numToShow;
   private String defaultScreenToShow;
}

My person XML is as such:

<hibernate-mapping package="com.example.entities">
    <id key column="PERSON_ID" /> <!-- Leaving out custom generator -->

     <!-- 
         Not sure what the column needs to be here, as 
         preferences are in own table.  Also read it has to 
         be a faked out many-to-one here as not all users will
         have preferences. 
     -->
    <many-to-one name="preferences" not-null="false" /> 
    <component class="com.example.entities.Name">
        <property column="first_name" name="first" />
        <property column="last_name" name="last" />
    </component>

</hibernate-mapping>

My preferences XML file is as such:

<hibernate-mapping package="com.example.entities">
    <property column="default_screen" name="defaultScreenToShow" />
    <property column="number_search_results" name="numToShow" />
    <!-- Not sure what the ID needs to be here -->
</hibernate-mapping>

I’m pretty green with Hibernate in all honesty, but this seems like something which should be pretty easy to map in. I thought I had the mappings done properly, but I get a deserialization exception upon trying to load a person (I’ve marked the classes as Serializable — to no avail).

  • 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-23T00:41:36+00:00Added an answer on May 23, 2026 at 12:41 am

    I was able to solve this in my desired way (Annotating the new class, and adding to the XML of the old class — When I used XML in each situation, I was only able to store the Ordinal value of the enum, which wasn’t desired).

    Person.hbm.xml
    <join table="PREFS_JOIN_TABLE" optional="true">
        <key column="PERSON_ID" />
        <many-to-one name="preferences" column="PREFERENCES_ID" not-null="true" unique="true" cascade="all"/>
    </join>
    

    My new class, which I was able to annotate, now looks like:

    @Entity
    @Table(name = "PREFERENCES")
    public class UserPreferences implements Preferences {
        private Long id;
        private Panel defaultPanelToShow;
        private Person person;
    
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="prefSeq")
        @SequenceGenerator(name="prefSeq", sequenceName = "SQ_PREFERENCES_ID", allocationSize = 10, initialValue = 1)
        @Column(name="PREFERENCES_ID")
        public Long getId() {
            return id;
        }
    
        @Column(name="DEFAULT_USER_PANEL")
        @Enumerated(EnumType.STRING)
        public Panel getDefaultRequestPanel() {
            return defaultPanelToShow;
        }
    
        @OneToOne
        @JoinTable(name="PREFS_JOIN_TABLE", joinColumns=@JoinColumn(name="PREFERENCES_ID", unique=true), inverseJoinColumns=@JoinColumn(name="PERSON_ID", unique=true))
        public Person getPerson() {
            return person;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a some classes which I need to serialize in two different ways:
I have two classes which extend Activity and need to call another class method
I have two related classes which share a common interface and are both stored
I have two classes one of which inherits from the other. Im trying to
I have two Java classes: B, which extends another class A, as follows :
I have a MustInherit Parent class with two Child classes which Inherit from the
I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend
I have a class which has two HashSet<String> collections as private members. Other classes
I have two classes that each need an instance of each other to function.
I have recently been put in charge of debugging two different programs which will

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.