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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:51:29+00:00 2026-06-14T10:51:29+00:00

I have 2 tables event & location in the public schema. I have two

  • 0

I have 2 tables event & location in the public schema. I have two tables in the ‘other’ schema which inherit from the public tables. There are 4 classes that mimic this setup (Event, Location, OtherEvent, & OtherLocation). I’m trying to use Hibernate to persist the OtherEvent & Other Location.

Every Event has 1+ Locations. A Location is meaningless with an Event.

If I create an OtherEvent and add an OtherLocation to it and try to save it, hibernate inserts the OtherEvent into other.event & hibernate inserts the OtherLocation into other.location (including the event_id).
Then hibernate tries to do: UPDATE public.location set event_id=? where location=?
This fails because I don’t have permission on public.location. How can I prevent it from doing this update? Or change it so it does the update on the other.location table.

I tried modifying public.hbm.xml and changing:

<bag name="locations">

to

<bag name="locations" inverse="true">

This doesn’t do the update statement, but the insertion into other.location doesn’t include the event_id column (causing a ConstraintViolation on the not null). This would be because the Location doesn’t have a reference to the Event object.

I cannot change the DB at all. I am using Hibernate 4. What do I do?

Here is all of the relevant configs:
Public Classes:

public class Event{
    private String eventId;
    private List<Location> locations;
    //getters & setters
}

public class Location{
    private String locationId;
    private double lat;
    private double lon;
    //getters and setters
}

Public Tables:

create table public.event{
    event_id varchar PRIMARY KEY,
    event_name varchar,
)

create table public.location(
    location_id varchar PRIMARY KEY,
    event_id varchar NOT NULL, --foreign key to public.event.event_id
    lat double,
    lon double
)

public.hbm.xml:

<hibernate-mapping schema="public">
    <class name="Event" table="event">
        <id name="eventId" column="event_id"/>
        <bag name="locations">
            <key column="event_id" not-null="true"/>
            <one-to-many class="Location">
        </bag>
    </class>
    <class name="Location" table="location">
        <id name="locationId" column="location_id"/>
        <property name="lat" column="lat"/>
        <property name="lon" column="lon"/>
    </class>
</hibernate-mapping>

Other Tables:

create table other.event inherits public.event(
    other_information varchar
)

create table other.location inherits public.location(
    other_loc_information varchar
)

Other Classes:

public class OtherEvent extends Event{
    private String otherInformation;
    //getter & setter
}

public class OtherLocation extends Location{
    private String otherLocInformation;
    //getter & setter
}

other.hbm.xml:

<hibernate-mapping schema="other">
    <union-subclass name="OtherEvent" extends="Event" table="event">
        <property name="otherInformation" column="other_information"/>
    </union-subclass>
    <union-subclass name="OtherLocation" extends="Location" table="location">
        <property name="otherLocInformation" column="other_loc_information"/>
    </union-subclass>
</hibernate-mapping>
  • 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-06-14T10:51:30+00:00Added an answer on June 14, 2026 at 10:51 am

    I would say that the solution is very close. You said:

    I cannot change the DB at all. I am using Hibernate 4. What do I do?

    So I expect that you can change the code and mapping. If I am right and you can change the code and mapping: the setting inverse you’ve tried:

    <bag name="locations" inverse="true">
    

    should solve it. Only thing in this case is, that we also have to explicitly assign Location to Event (not only put it into owning collection).

    Location should have a property Event

    public class Location{
        private String locationId;
        private Event event;
        private double lat;
        private double lon;
        //getters and setters
    }
    

    The mapping should be:

    <class name="Location" table="location">
      <id name="locationId" column="location_id"/>
      <property name="lat" column="lat"/>
      <property name="lon" column="lon"/>
      <many-to-one name="Event" column="event_id" />
    </class>
    

    So if in the code you will do:

    event.locations.add(location);
    location.event = event;
    

    Then it should work with INSERTS only. The inverse means, that child will do all the stuff alone, so it has to know about parent.

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

Sidebar

Related Questions

I have 3 tables event, location, event_location. Event can have multiple locations. Location table
I have got two tables: Event +----------+---------+--------------+ | event_id | name | date |
I have two tables, events and photos, which relate together via the 'Event_ID' column.
I have two tables: candidate_register_table with the following schema: |----------------------------------------------------| | username | name
I have two tables linked via a HABTM. countries & networks. They are linked
I have 5 tables that I wish to get data from all linking to
I have two tables: events and events_actions events columns: event_id user_id event_name events_actions columns:
Let's say you have three tables named Item, Event, and Seat, constructed as such:
I'm designing a staff rota planner....have three tables Staff (Staff details), Event (Event details),
I have two auditing tables: Trip_aud and Event_aud. They were created in Envers, but

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.