1

I use ActiveJDBC and Oracle 11g DB. When I use saveIt, i get java.sql.Exception. When I get instance or list of it, everything ok. What I do wrong?

Exception in thread "main" org.javalite.activejdbc.DBException: java.sql.SQLException: Invalid argument
зове, query: INSERT INTO dept (DEPTNO, DNAME, LOC) VALUES (?, ?, ?), params: 45, sdfa, fdg
        at oracle.jdbc.driver.AutoKeyInfo.getNewSql(AutoKeyInfo.java:187)
        at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:5704)
        at org.javalite.activejdbc.DB.execInsert(DB.java:598)
        at org.javalite.activejdbc.Model.insert(Model.java:2698)
        at org.javalite.activejdbc.Model.save(Model.java:2597)
        at org.javalite.activejdbc.Model.saveIt(Model.java:2524)
        at JavaHomeTask.Dept.addPersistence(Dept.java:72)
        at JavaHomeTask.App.addRow(App.java:103)
        at JavaHomeTask.App.main(App.java:50)
Caused by: java.sql.SQLException: Invalid argument
        ... 9 more

And here is my code:

public void addPersistence() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Dept d = new Dept();
        String value;
        for (String s : getAttributesNames()) {
            System.out.println("Enter " + s + " and press Enter button:");
            value = reader.readLine();
            d.set(s, value);
        }
        d.saveIt();

    }

public List<String> getAttributesNames() {
        return Arrays.asList("DEPTNO", "DNAME", "LOC");
    }
alex
  • 942
  • 1
  • 10
  • 26
  • can you publish entire stack trace? Also, I think one of your parameters has something wrong with it, so Oracle complains. – ipolevoy May 13 '15 at 19:59
  • @ipolevoy It seems like it's entire stack trace. Schema of table dept, in which i try to insert row is deptno Number(3) dname varchar2(14) loc varchar2(13) I've also tried such way: Dept d = new Dept(); d.set("deptno", Integer.valueOf(11)); d.set("dname", "name"); d.set("loc", "location"); d.saveIt(); But the result is the same. PS Sorry for my bad English. – alex May 15 '15 at 20:18
  • I found these topic https://github.com/javalite/activejdbc/issues/385 Seems like I have the same problem, there is no id column in my table. Am I right? – alex May 15 '15 at 20:26

1 Answers1

2

The reason of the probleb is that ActiveJDBC uses id column as a Primari Key in table for recognizing which operation - INSERT or UPDATE should be used. And if table doesn't has such column, programmer should specify PK manually using @IdName("nameOfColumn") annotation. More information you can find here

alex
  • 942
  • 1
  • 10
  • 26