taltun taltun

Greenhorn
+ Follow
since Mar 18, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by taltun taltun

Hi,

I have an User with 2 columns "username" and "status" as uniqueconstraints on table level as you can see in below example code. That seems to work fine.

The status column can contain "Active" or "Inactive".

I need to have multiple rows in User table with same username and the status value "Inactive", but only one row with the username and status "Active". Like below example:

User table
--------------------------------
ID Username Status
1 xx@xx.com Active (Only if the status is active should be unique constaint)
2 xx@xx.com Inactive
3 xx@xx.com Inactive
.....
--------------------------------


Code example:
-----------------
@Table(name = "user", uniqueConstraints=@UniqueConstraint(columnNames = {"username","status"}))
public class User extends BaseObject implements Serializable, UserDetails {

....

}

I hope some can help....

-taltun
Hi,

Currently when I have an object User with e.g. Message

public class User {
private Long id;
private Message message = new Message("My Message");
...
}

public class UserService {

public saveUser(User user) {

// Currently I have this solution. I don't like this solution.
Message message = messageDao.save(user.getMessage);
user.setMessage(message);
userDao.save(user)

// I need this solution.
// The depended Message object is persisteted too automaticly without explicitly
// persist the message object before persisting the user obect separatly like above example.
userDao.save(user);

}
}

Is this possible ?

-taltun
Hi,

I have problem with solving below solution which I have spent too much time:

An User domain object need to have 2 collections.

1. One representing a collection of Document objects that the user have created/is owner of.
Example:
private Set<Document> myDocumentsSentToOther = new HashSet<Document>()

2. Another representing a collection of Document objects that other users have created/owner of but sent to this User.
Example:
private Set<Document> othersDocumentsSentToMe = new HashSet<Document>()

public class User {
private Long id;
private Set<Document> myDocuments = new HashSet<Document>()
private Set<Document> othersDocuments = new HashSet<Document>()
....
}

public class Document {
private Long id;
private User owner;
....
}

As I see it is a Many-To-Many relationship because an User can create and send many Document to other users and receive many Documents sent by other users. Therefore, I need a way to get both collections, those I have sent to others and those other users have among other thing sent to me and I need to seperate them in two collections.

How do I code this in JPA ?

Please, provide annotation based code examples of above two domain objects.

Please provide code examples.

Thank you very much...

-taltu