Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.save() method throws error #189

Closed
artdaw opened this issue May 31, 2013 · 3 comments
Closed

.save() method throws error #189

artdaw opened this issue May 31, 2013 · 3 comments

Comments

@artdaw
Copy link
Contributor

artdaw commented May 31, 2013

Original author: yzh...@onescreen.com (March 01, 2013 23:16:12)

What steps will reproduce the problem?

  1. create a table with composite key as primary key: for example:
    CREATE TABLE segments (
    segment_id bigint(20) NOT NULL,
    domain_id int(11) NOT NULL,
    PRIMARY KEY (segment_id,domain_id)
  2. create an activeJDBC model
    public class Segment extends Model { ...
  3. insert the same primary key twice through the following code
    for(int i=0;i<2;i++) {
    Segment segment = new Segment();
    segment.setLong("segment_id", segmentId);
    segment.setInteger("domain_id", domainId);
    segment.save();
    }
  4. .save() function reached exception at the second time.

What is the expected output? What do you see instead?

according to the documentation: the method save() will silently exit without throwing exceptions..

and I reached exception:

What version of the product are you using? On what operating system?
1.4.6

Exception message:

org.javalite.activejdbc.DBException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '100-1' for key 'PRIMARY', Query: INSERT INTO segments (segment_id, domain_id) VALUES (?, ?), params: 100,1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
at org.javalite.activejdbc.DB.execInsert(DB.java:516)
at org.javalite.activejdbc.Model.doInsert(Model.java:2144)
at org.javalite.activejdbc.Model.save(Model.java:2051)
at my.model.Segment.save(Segment.java)
at my.model.Segment.setDomainOnSegment(Segment.java:35)
at my.model.Segment_JUnit.test(Segment_JUnit.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '100-1' for key 'PRIMARY'
... 46 more

Original issue: http://code.google.com/p/activejdbc/issues/detail?id=189

@artdaw
Copy link
Contributor Author

artdaw commented May 31, 2013

From i...@polevoy.org on March 01, 2013 23:23:16
Method save() will not throw exceptions only in case of validation exceptions.
Validations are described on page: http://code.google.com/p/activejdbc/wiki/Validations

ActiveJDBC does not manage composite PKs it is a developers responsibility to do this.
Framework works as expected.
Please, refer to page: http://code.google.com/p/activejdbc/wiki/SurrogatePrimaryKeys
for understanding of PKs in AJ

@artdaw
Copy link
Contributor Author

artdaw commented May 31, 2013

From i...@polevoy.org on March 02, 2013 00:59:21
if things are still not clear, ask a question on Google Group:
https://groups.google.com/forum/?fromgroups#!forum/activejdbc-group

@artdaw
Copy link
Contributor Author

artdaw commented May 31, 2013

From yzh...@onescreen.com on March 02, 2013 02:04:53
I see. I misunderstood the documentation. thanks I will handle the exception myself.

@artdaw artdaw closed this as completed May 31, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant