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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:46:36+00:00 2026-05-20T19:46:36+00:00

For some reason this is not persisting anything into tag_item table : Tag tag

  • 0

For some reason this is not persisting anything into tag_item table :

    Tag tag = new Tag();
    tag.setName("test");
    tag = (Tag) tagService.save(tag);

    Set<Tag> tags = new HashSet<Tag>();
    tags.add(tag);

    Item item = itemService.getByStringId(2);
    item.setTags(tags);
    itemService.save(item);

MySQL:

CREATE TABLE `tags` (
`tag_id` bigint(20) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE `tag_item` (
`tag_id` bigint(20) NOT NULL,
`item_id` bigint(20) NOT NULL,
PRIMARY KEY (`item_id`,`tag_id`),
KEY `FK_tag_item_tag_id` (`tag_id`),
KEY `FK_tag_item_item_id` (`item_id`),
CONSTRAINT `FK_tag_item_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`tag_id`),
CONSTRAINT `FK_tag_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `items`    (`item_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE `items` (
`item_id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`item_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

Xml Hibernate Mappings:

<id name="id" type="long" column="tag_id">
        <generator class="native"/>
</id>
    <property name="name" type="string" column="name"/>
    <set name="items" inverse="true" lazy="true" table="tag_item">
        <key>
              <column name="tag_id" not-null="true"/>
        </key>
        <many-to-many class="com.iteezy.shared.domain.Item">
              <column name="item_id" not-null="true"/>
        </many-to-many>
    </set>

<id name="id" type="long" column="item_id">
        <generator class="native"/>
</id>
    <property name="name" type="string" column="name"/>
    <set name="tags" inverse="true" lazy="true" table="tag_item">
        <key>
              <column name="item_id" not-null="true"/>
        </key>
        <many-to-many class="com.iteezy.shared.domain.Tag">
              <column name="tag_id" not-null="true"/>
        </many-to-many>
    </set>
  • 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-20T19:46:37+00:00Added an answer on May 20, 2026 at 7:46 pm

    You have a bidiectional many-to-many relationship, so you can use an example in 8.5.3. Many-to-many. Also see 7.3.1. Sorted collections for the way to configure a comparator (though it would be better to perform sorting at the database side with order-by).

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

Sidebar

Related Questions

For some reason this program is saying that 'switch' is not defined. What is
For some reason I'm not getting this. (Example model below) If I write: var
For some reason, this code does not actually draw my bitmap file... or show
For some reason the background does not appear. This is the CSS div.sidebar_beige {
For some reason I never see this done. Is there a reason why not?
For some reason, this MySQL fails: CREATE SCHEMA IF NOT EXISTS `partB` DEFAULT CHARACTER
For some reason This php script won't echo anything: <?php setcookie(pop,'hi',time()+604800); echo $HTTP_COOKIE_VARS['pop']; ?>
For some reason this is not working. Instead it thinks it should check the
For some reason this is not working, yet all my searches say it should
For some reason this does not look correct. Is there a better way 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.