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

  • Home
  • SEARCH
  • 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 6678087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:12:05+00:00 2026-05-26T04:12:05+00:00

Hi guys I’ve searched everywhere for this, so this is literally a last resort,

  • 0

Hi guys I’ve searched everywhere for this, so this is literally a last resort, I am trying to get a nice database structure for the following code:

@Entity
@Table(name = "tasks")
@XmlRootElement(name = "task")
@XmlType(propOrder = { "id", "taskTitle", "notifications" })
public class Task {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "identifier")
    private String taskTitle;

    @OneToMany(mappedBy = "???super.task???", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Set<User> users;

    @OneToMany(mappedBy = "task", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Set<Group> groups;

    @XmlElement(name = "notify_list")
    public Notify getNotifications() {
        return new Notify(this);
    }
... (the users and groups getters are XmlTransient)
}

@XmlAccessorType
@XmlType(propOrder = { "users", "groups" })
public class Notify {
    private Task task;
    public Notify() {
        super();
    }

    public Notify(Task task) {
        this.task = task;
    }

    @XmlElementWrapper(name = "users")
    @XmlElements({ @XmlElement(name = "user") })
    public Set<User> getUsers() {
        return task.getUsers();
    }

    @XmlElementWrapper(name = "groups")
    @XmlElements({ @XmlElement(name = "group") })
    public Set<Group> getGroups() {
        return task.getGroups();
    }
}

@MappedSuperclass
public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ManyToOne
    private Task task;

    @Column(name = "person_id")
    private Integer personId;

    @Transient
    private String firstName, lastName, email;

...(public getters/setters here)
}

@Entity
@Table(name = "persons")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "group_or_user")
@DiscriminatorValue(value = "group")
@XmlAccessorType
@XmlType(propOrder = { "personId", "firstName", "lastName", "email" })
public class Group extends Person {
    ...(inherits everything from Person and defines XmlElements)
}

@Entity
@DiscriminatorValue(value = "user")
@XmlAccessorType
@XmlType(propOrder = { "username", "personId", "firstName", "lastName",
    "email", "phone" })
public class User extends Group {

    @Transient
    private String username, phone;

    @XmlElement(name = "username")
    public String getUsername() {
        return username;
    }

    @XmlElement(name = "phone")
    public String getPhone() {
    return phone;
    }

...(the other getters/setters are inherited)
}

also i want my xml like this:

<task>
    <id>10001</id>
    <identifier>Title of the task</identifier>
    <notify_list>
      <users>
        <user>
          <username>firstname.lastname</username>
          <person_id>12</person_id>
          <firstname>FirstName</firstname>
          <lastname>LastName</lastname>
          <email>me@myname.com</email>
          <phone>023545848796</phone>
        </user>
      </users>
      <groups>
        <group>
          <person_id>21247415</person_id>
          <firstname>PizzaGroup</firstname>
          <lastname>Pizza</lastname>
          <email>blabla@something.com</email>
        </group>
      </groups>
    </notify_list>
</task>

and by nice db structure i mean: 1 table for the task and 1 table for persons(with a discriminator column of course). As you can see i ran into a problem with the OneToMany relationship on the Set of users because it sais that “it can’t find any reference to the unknown target entity i mapBy for the users i.e. the task, which is defined in the MappedSuperclass Person so from what i know it should inherit it because Group inherits it. So the question actually is: what am i doing wrong?

EDIT:

i forgot to mention that i can persist only the person_id’s for the users and groups and that the rest i get from another db, but that’s another story 🙂

  • 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-26T04:12:06+00:00Added an answer on May 26, 2026 at 4:12 am

    The mappedBy attribute value should be “task”. The problem is that the task field in Person is of type MaintenanceTask instead of Task.

    Also, make sure all the entities are listed in the hibernate configuration file.

    But I think this mapping won’t work, because you try to define two different associations on one side, mapped by a single one (and a single column) on the other size. Since the collection of groups will also hold the users (as User extends Group), you should probably remove the users set in the task. Just provide two getters that return a filtered collection, based on the actual type of the group.

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

Sidebar

Related Questions

Guys, I am trying to find a nice panel like control for ASP.NET. I'd
Guys, I have the following code that is inside a big while loop that
Guys this code is returning false in a blank page after submit.What is the
guys. I tried this code: def trap_check(payroll[][], timelive[][]) . . . end I was
guys, I would like to you evaluate next code below. As you see, I
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
Guys In node.js, mongolian or mongo-native is not supported group function? mongo-native code, var
Guys I'm getting this really weird fault with my program when I run it.
guys i'm still new on developing system and I've encountered this This is the
guys. I'm trying to call some AJAX Post trhu AngularJS, and I want to

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.