Persist « Field « JPA Q&A

1. JPA fastest way to ignore a field during persistence?

I'm essentially looking for a "@Ignore" type annotation with which I can stop a particular field from being persisted. How can this be achieved?

2. JPA set TIMESTAMP field to CURRENT_TIMESTAMP when persisting

I have a TIMESTAMP column on a table that is set to null when a record is initially inserted. I would like to update the value to the current time. ...

3. Persist collection fields with hibernate

Using hibernate, how can I persist a class with a List<String> field? Consider the following entity class:

public class Blog {
    private Long id;
    private List<String> list;


4. How to persist an entity which contains a field of user type using JPA2

I'm looking for a way to persist an entity which contains a field of a user type. In this particular example I would like to persist the ts field as number ...

5. JPA and unique fields

I have two persistence objects in my app: Things and tags attached to things. The app can generate collections of things with tags attached. Tag objects have a unique name (it ...

6. JPA: how do I persist a String into a database field, type MYSQL Text

The requirement is that the user can write an article, therefore I choose type Text for the content field inside mysql database. How can I convert Java String into MySQL Text Here ...

7. How to persist an object that has an enumeration field

I'm using an enumeration in my domain model, but I get the following error when I try to persist an object to the database:

Exception in thread "main" java.lang.ClassCastException: cannot be ...

8. Hibernate - How to persist an entity but disregarding certain fields?

I have an Entity with several fields:

public class Leilighet {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private Long leilighetId;
private String navn;
private String beskrivelse;
private String adresse;
private String postNr;
private String postSted;
private double pris;

//The following fields should not ...

9. How to tell JPA to use a field of a simple class as the persistence value?

Consider this class:

class Bar {
    private long id;
    private FooId fooId;
    /* ... */
Where Foo is basically just:
class ...

10. Persisting JPA entities with entity fields possible?

If I have an entity such as the following:

public class Customer {
    private Address address;
And the Address is also an entity:
public class Address {...}
Does persisting the Customer in ...

11. Non persistent class with persistent fields

I have following database design: A Project has multiple Categories : stored in ProjectCategory table with ProjectId as one column A Project has multiple Types: stored in ProjectType table with ProjectId as one column A Project has multiple Locations: stored in ProjectLocation table with ProjectId as one column The Project will have other properties associated with it in Project table. Now ...

12. Problem persisting to a table that contains a blob field

Hi all, I've been having a problem trying to persist an object that maps an object to a table that contains a blob field. I read this link and created the BinaryBlobType and the mapping as directed and I'm still having problems. I also tried one of the solutions from the page, which was to change the batch_size to 0, ...

13. Newbie question: getting some fields back from a persisted o

Need help with Hibernate? Read this first: ... AskForHelp Hibernate version: 3.x Mapping documents:

14. Clobs in same table persisting in wrong DB fields

I am using hibernate 3.0 with an Oracle database. I have a document table that has 3 CLOBs. One called "document", another called "history" and a third called "formattedText". On occassion, when I persist the document object, the value that is in the document property is persisted in the history field and vice-versa. I've put checks in the object's setter and ...

15. non persistent field

16. How can I persist the order of a collection in a DB field?

Hello All, Im using Hibernate 3 with a legacy application on an oracle9i database. We are persisting data that has a field named "node order." The data represents a hierarchy tree (similar a file tree like windows explorer). I would like to create a SortedSet of 3 items and have their order persisted. For example, Id like the application to persist. ...

17. Persist one-to-one field object

class Order { Lond id; Date ts; double amount; State state; // getters and setters... } class State { Long id; String desc; int qty; ... ...

18. Not persisting all fields of an object.

Hello, I am currently working on a Hibernate system. I have an object that stores the password of a client. However this objet also stores the email address of this client. My problem is that each time the user changes his email he has to change the password. If he leaves the password empty, it will ba saved as an empty ...

19. Need to persist a field that was previously derived

Hi, I have a contract domain object. The contract object contains SETs of contract Line items and other various properties that my app uses. At present, calculating the contract cost is done via a call to a getTotalContractCost() method. This is transient method. The method checks the dependent objects as necessary. This works well. Now the users want to store the ...

20. Insert images into Blob fields using Hibernate & Persist

am a little confused on how to insert images into blob fields in database. In the entity class should the field be of type Blob? for example: @Entity @Table (name = "images") public class Pic { @Id @Column(name = "name") private String name; @Column (name= "picture") private Blob picture; I am not sure how to go about it. please provide suggestions ...

21. How to Persist an object in different tables based on field

I have an object Property and it has fields like private City city; private TransactionType transaction_type; For some cities and transaction_types I want to store them in different tables (to optimize queries - not sure if its the correct approach). 1)How can it be done? 2)I am not sure if storing in different tables after checking the values of fields is ...

22. VERY weird - Hibernate persisting all fields when shouldnt

@Test public void testPostNewJob() { setCurrentUser( new EmployerUser() ); Job job = new Job(); job.setPositionName( "name" ); job.setDescription( "description" ); job.setExcerpt( "exerpt" ); ...