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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:34:08+00:00 2026-05-30T19:34:08+00:00

I’m just starting to learn Java database persistence using Hibernate ORM and have run

  • 0

I’m just starting to learn Java database persistence using Hibernate ORM and have run into a problem which I haven’t been able to resolve.

I have these two classes:

@Embeddable
public class Resource {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Resource() {
    }
}

@Entity
public class Group {

    @Embedded
    private Map<String, Resource> resources;

    @Id
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map<String, Resource> getResources() {
        return resources;
    }

    public void setResources(Map<String, Resource> resources) {
        this.resources = resources;
    }

    public Group() {
        resources = new HashMap<String, Resource>();
    }
}

The Resource shouldn’t have its own table because it shouldn’t exist outside the Group scope. That’s why I used the Embeddable, to be treated as a component.

To sum up I’d like to know how I can store these classes in a database using Hibernate ORM. The Resource class shouldn’t be an Entity as it doesn’t need its own class.

And I would prefer to use the mapping notations and not XML files.

As it is I get this error:

Syntax error in SQL statement "INSERT INTO GROUP[*] (NAME) VALUES (?) "; expected "identifier"; SQL statement:
  • 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-30T19:34:10+00:00Added an answer on May 30, 2026 at 7:34 pm

    It is possible to save all instances of Resource belonging to certain Group to the same database row with Group itself by creating class that wraps inside groups and saving it as Serializable to BLOB field in database.

    Because such a solution asks more code and produces confusing data model, it is unlikely that you really want to limit yourself to have only one table.

    If, as you said, Resource is fully owned by Group and you want to access them by some string key then @ElementCollection containing instances of embeddable Resource is solution (assuming that your version of Hibernate already have it):

    @ElementCollection
    private Map<String, Resource> resources;
    

    If you do not have access collection of Resource by name, then following is sufficient

    @ElementColection
    private Set<Resource> resources;
    

    For more examples about fine tuning your element collection can be found from: Java Persistence/ElementCollection

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I would like to run a str_replace or preg_replace which looks for certain words
I have a reasonable size flat file database of text documents mostly saved in

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.