-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ManyToMany ( mappedBy = ..
PostPosted: Wed Apr 23, 2008 8:05 am 
Newbie

Joined: Mon Apr 14, 2008 7:44 am
Posts: 4
User.class

Code:
@ManyToMany(
            cascade={CascadeType.PERSIST, CascadeType.MERGE},
            mappedBy="users",
            targetEntity=Service.class
    )   
    private Set<Service> service;
    public Set<Service> getService() {
        return service;
}




Service.class
Code:
@ManyToMany (
            targetEntity = User.class,
            cascade = {CascadeType.PERSIST, CascadeType.MERGE}
    )
@JoinTable(
            name = "SERVICE_USERS",
            joinColumns = @JoinColumn ( name="SERVICE_ID" ),
            inverseJoinColumns = @JoinColumn(name = "USER_ID")
    )
private Set<User> users;
public Set<User> getUsers() {
        return users;
}


then

Code:
Service service = new Service();
      
service.setTitle("Delete folders");
service.setDescription("Desription of service");
service.setDate( new Date() );
service.setCount( 0 );

User user = new User();
user.setFio("Ivanov Sergei Ivanovich");
user.setCreateDate(new Date());
user.setUpdateDate(new Date());
Set <User> set =  new HashSet <User>();
set.add(user);
service.setUsers(set);

ORMHelper.update(service); // error


but I still get error:
Code:
Hibernate: /* insert ru.mipt.rivis.hib.example.Service */ insert into Service (COUNT, DESCRIPTION, LASTCALLDATE, TITLE) values (?, ?, ?, ?)
Hibernate: /* insert collection row ru.mipt.rivis.hib.example.Service.users */ insert into SERVICE_USERS (SERVICE_ID, USER_ID) values (?, ?)
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ru.mipt.rivis.hib.example.User



What's wrong?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.