Re: Comment on WhatsSupported in simplejpa

16 views
Skip to first unread message

simp...@googlecode.com

unread,
Oct 21, 2010, 7:07:59 AM10/21/10
to simp...@googlegroups.com
Comment by fernandouhu:

If you want to make a OneToOne relation the following code does the trick:
@OneToOne
@Column(name="class_id")

Where class is the name of the class being related to this entity. For
example, if it's the class User:

@OneToOne
@Column(name="user_id")

Regards.


For more information:
http://code.google.com/p/simplejpa/wiki/WhatsSupported

simp...@googlecode.com

unread,
Feb 14, 2011, 7:13:20 AM2/14/11
to simp...@googlegroups.com
Comment by nehaver...@gmail.com:

How to I enable @OneToMany relationship?
survey.setSurveyId(RandomUUID.getUUID(10));
survey.setStartDate(new Date());
survey.setName("sgsdfgsdfh");

SDBDomain domain = new SDBDomain();
domain.setSurvey(survey);
survey.getDomains().add(domain);

domain = new SDBDomain();
domain.setSurvey(survey);
survey.getDomains().add(domain);


EntityManager em = getEntityManager();
em.persist(survey);
em.close();

this does not store the domains.

simp...@googlecode.com

unread,
Nov 30, 2013, 8:20:59 PM11/30/13
to simp...@googlegroups.com
Comment by marc.win...@gmail.com:

*Persisting Boolean Type*
So, this may be obvious to those more familiar to JPA in general, but since
I'm new to both SimpleJPA and JPA, I just figured this out on my own. In
order to handle accommodating a persisted Boolean type, I've done the
following in my project. It's obvious that you can use something other than
a Boolean for storage and get the same behaviour, I just liked how the
getters and setters as outlined below encapsulated those details and kept
the same set of method names as though it was stored as a Boolean type.
Also, this is not the most efficient use of space since a String holding
true or false of course uses more space than the single bit that's actually
required.

* Because you can't directly store Boolean values, use the variable you
want as a String
* Create the usual is*** and set*** for the variable as if it were a
Boolean. I returned the boolean primitive so it would work well with Spring
templates.
* Create a get*** method for the variable that returns a String. This is
what SimpleJPA will call when persisting the object.

Here's what some example code looks like then:

{{{

//...

private String verified = "false";

public String getVerified(){
return verified;
}

public boolean isVerified() {
return verified.equalsIgnoreCase("true");
}

public void setVerified(boolean verified) {
this.verified = verified?"true":"false";
}
//...

simp...@googlecode.com

unread,
Nov 30, 2013, 8:24:59 PM11/30/13
to simp...@googlegroups.com
Comment by marc.win...@gmail.com:

Persisting Boolean Types

So, this may be obvious to those more familiar to JPA in general, but since
I'm new to both SimpleJPA and JPA, I just figured this out on my own. In
order to handle accommodating a persisted Boolean type, I've done the
following in my project. It's obvious that you can use something other than
a Boolean for storage and get the same behaviour, I just liked how the
getters and setters as outlined below encapsulated those details and kept
the same set of method names as though it was stored as a Boolean type.
Also, this is not the most efficient use of space since a String holding
true or false of course uses more space than the single bit that's actually
required.

Because you can't directly store Boolean values, use the variable you want
as a String Create the usual is and set for the variable as if it were a
Boolean. I returned the boolean primitive so it would work well with Spring
templates. Create a get method for the variable that returns a String. This
is what SimpleJPA will call when persisting the object.

Here's what some example code looks like then:
{{{
//...

private String verified = "false";

public String getVerified(){
return verified;
}

public boolean isVerified() {
return verified.equalsIgnoreCase("true");
}

public void setVerified(String verified) {
this.verified = verified;
Reply all
Reply to author
Forward
0 new messages