-->
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.  [ 3 posts ] 
Author Message
 Post subject: Pojo Annote.Want to leave some Getter/Setter un-mapped
PostPosted: Mon Feb 16, 2009 2:49 pm 
Newbie

Joined: Mon Feb 16, 2009 2:27 pm
Posts: 7
What I am trying to do is create a Pojo that has the majority
of its Getters/Setters mapped to a a column in the table,

The table is then fully mapped but I also leave two gettings and setters un-mapped.

These un-mapped fields will be given values later just before the class is sent to the view to be displayed on the web page.

I only want to store a long value of a date in Milliseonds.
Then in the controller convert it to a real date and store it in that
object of this Class. I just want to keep all the data together
but not have to store the string value in the database.

Code:
@Entity
@Table(name = "date_info", catalog = "dates")
public class DateInfo implements java.io.Serializable {

private Integer id;
private long dateStart;
private long dateEnd;
private String dateStartString;
private String dateEndString;

public DateInfo() {
   }


public DateInfo(long dateStart, long dateEnd, String dateStartString, String dateEndString) {

      this.dateStart = dateStart;
      this.datrEnd = dateEnd;
      this.dateStartString = dateStartString;
      this.dateEndString = dateEndString;
   }


@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID", unique = true, nullable = false)
public Integer getId() {
   return this.id;
}

public void setId(Integer id) {
   this.id = id;
}


@Column(name = "DT_START", nullable = false)
public long getDateStart() {
   return this.dateStart;
}

public void setDateStart(long dateStart) {
   this.dateStart = dateStart;
}

@Column(name = "DT_END", nullable = false)
public long getDateEnd() {
   return this.dateEnd;
}

public void setDateEnd(long dateEnd) {
   this.dateEnd = dateEnd;
}


//Don't want to map these fields as I will be filling them in later
//When i am manipulating data. I don't need to store these,
//Only keep them within this class so i can use them in the returned view.
public String getDateStartString() {
   return this.dateStartString;
}

public void setDateStartString(String dateStartString) {
   this.dateStartString = dateStartString;
}


public String getDateEndString() {
   return this.dateEndString;
}

public void setDateEnd(String dateEndString) {
   this.dateEndString = dateEndString;
}





Any ideas?

Is there anyway i can leave a Column mapping blank? or Declare it
not mapped to anything and ignore the getter and setter?

Thanks


Top
 Profile  
 
 Post subject: Pojo Annote.Want to leave some Getter/Setter un-mapped
PostPosted: Mon Feb 16, 2009 4:29 pm 
Newbie

Joined: Sun Feb 15, 2009 11:36 am
Posts: 9
Location: Switzerland
Hi Daxon

@Transient does the trick:

Code:
@Transient
public String getDateStartString() {
   return this.dateStartString;
}

_________________
Regards,
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 4:45 pm 
Newbie

Joined: Mon Feb 16, 2009 2:27 pm
Posts: 7
Thats perfect!

Works like a charm :)

Thanks


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

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.