Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Temporal Type in Dynamic JPA
Temporal Type in Dynamic JPA [message #988921] Mon, 03 December 2012 17:37 Go to next message
khalil haddad is currently offline khalil haddadFriend
Messages: 12
Registered: November 2012
Junior Member
Hello,

I'm using the EclipseLink feature called Dynamic which permits to create entity types at runtime. Dynamic
I create mirror entities to audit some business entities. Cool
All works fine and the only problem I have is with date fields.
I don't figure out how to set the temporal type of a field as equivalent to the JPA annotation @Temporal... (Date, Time or Timestamp) Shocked
I create my DynamicType with a JPADynamicTypeBuilder and call addDirectMapping method to add a field.
I found this doc but I think it's outdated : http://wiki.eclipse.org/EclipseLink/Development/Dynamic#JPA_CRUD_Examples

Has someone ever used Dynamic JPA and can help me? Rolling Eyes

Re: Temporal Type in Dynamic JPA [message #989066 is a reply to message #988921] Tue, 04 December 2012 13:55 Go to previous message
khalil haddad is currently offline khalil haddadFriend
Messages: 12
Registered: November 2012
Junior Member
I finally found a solution. Here it is if someone needs it :

	private void buildDateMapping(String fieldName, String attributeName, TemporalType tt, JPADynamicTypeBuilder builder){
		DirectToFieldMapping mapping = new DirectToFieldMapping();
        mapping.setAttributeName(attributeName);
        mapping.setFieldName(fieldName);
        
        Class<?> fieldClassification;
        if (tt.equals(TemporalType.DATE)) {
        	fieldClassification = java.sql.Date.class;
        } else if(tt.equals(TemporalType.TIME)) {
        	fieldClassification = java.sql.Time.class;
        } else {
            // TIMESTAMP
        	fieldClassification = java.sql.Timestamp.class;
        }        

        mapping.setFieldClassification(fieldClassification);
        mapping.setConverter(new TypeConversionConverter(mapping));
        
        builder.addMapping(mapping);
	}
Previous Topic:Error on Test #2 JPA/DCN Example Code
Next Topic:one to many bidirectional self reference - problem
Goto Forum:
  


Current Time: Thu Mar 28 09:54:31 GMT 2024

Powered by FUDForum. Page generated in 0.03865 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top