0

I have a model for Ex: Library

@Entity
@Table(name = "STR_LIBRARY")
@EGSIDGenerator(sequenceName = "SEQ_ICT")
public class Library extends Auditable implements Serializable {

    private static final long serialVersionUID = -7276332695447103176L;

    @Id
    @Column(name = "ICT_ID")
    private Long id;

    @Column(name = "BOOK_ID")
    private Long bookID;

    @Column(name = "START_DATE")
    private Date startDate;

    @Column(name = "END_DATE")
    private Date endDate;
    ../getters and setters/

My RepositoryImplementation

@Repository("libraryRepo")
public class LibraryRepositoryImpl extends AbstractJPARepository
        implements LibraryBatchRepository<Library> {

    @Override
    public List<Library> saveData(List<Library> dataList) {
        // TODO Auto-generated method stub
        List<Library> savedList = new ArrayList<Library>();

        for (Library t : dataList) {

            savedList.add(getEntityManager().merge(t));
        }

        return savedList;
    }

My Client side , saves the below data but while update throws error

[{
  "bookID"              :196,
  "startDate"           :"2015-08-27",
  "endDate"             :"2015-08-27",
  "id"                  :null
 }]

whereas i am updating any field

 [{"bookID"              :196,
      "startDate"           :"2015-08-27",
      "endDate"             :"2015-08-28",
      "id"                  :201}]

throws the following error:

ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-01858: a non-numeric character was found where a numeric was expected

Do i need to change the date format here?

AnithaRaj
  • 147
  • 1
  • 2
  • 10
  • Try keeping "id" value constant and non-null (primary key) and update "bookId", and check if still you are getting error. Also, I think, lenght field won't be useful for Date datatype as it is specifically used for String valued column. – Ashish Patil Jul 28 '15 at 05:56
  • @Utkarsh thanks for your reply. i am not updating primary key. i want to update the field for an existing record with id 201. – AnithaRaj Jul 28 '15 at 06:10
  • First of all you should annotate `@Temporal(TemporalType.DATE)` over date fields and why have you given `length = 7` , what is the data type of that Column in DB ? – Utkarsh Jul 28 '15 at 06:22
  • @Utkarsh the data type is Date. i have removed the length field as per the comments above. @Temporal(TemporalType.DATE) is it necessary. i will edit the post – AnithaRaj Jul 28 '15 at 06:28
  • Can you provide your entire stack trace ? It is not clear what you are doing ? – Utkarsh Jul 28 '15 at 06:30
  • initially the data type in the model was Calendar and i thought this error might be due to the date format as i found in most of the search answers. – AnithaRaj Jul 28 '15 at 06:33
  • can anyone provide sample code how do you update your entity with sample json data – AnithaRaj Jul 28 '15 at 06:42
  • How were you converting JSON to JAVA pojo? I am guessing your date fields are `null` while you are trying to update. You need to use JSON library like gson or jackson in order to convert JSON to JAVA. Please read this post : http://stackoverflow.com/questions/1395551/convert-a-json-string-to-object-in-java/ . You should provide complete stack trace otherwise its a lot of guess work – Utkarsh Jul 28 '15 at 06:47

0 Answers0