by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Andy Jefferson
    @andyjefferson
    You solve your wonderment by debugging your problem. It "works for me". It is as simple as it shows in the docs http://www.datanucleus.org:15080/products/accessplatform_5_1/jdo/mapping.html#auditing
    HUANG Zhiteng
    @zhiteng
    My code looks exactly the same, that's why I felt awkward using this annotation.
    HUANG Zhiteng
    @zhiteng
    OK, I think I got why CreateTimestamp would return '1970-01-01 07:59:59', it happens when PersistentManager.makePersistent() is called without having it in a Transaction. '1970-01-01 07:59:59' is the initial value (-1L) of 'beginTime' of Transaction class.
    Andy Jefferson
    @andyjefferson
    OK, So if you want to use such things nontransactional then raise an issue in GitHub, and provide a pull request
    bkalbfus
    @bkalbfus
    Hi, I have an issue that I can't find a testcase to start from to submit it with. I submitted this issue to Apache Isis that was using version 5.6 or Datanucleus - it involves the FederatedStoreManager and JDOQLTypedQueryImpl. The Apache issue is https://issues.apache.org/jira/browse/ISIS-2020
    I'd have to have a test case that would set up a Federated Data Store with a secondary data store, like is configured in the sample I submitted on the Apache board.
    Andy Jefferson
    @andyjefferson
    Hi, testcases are defined by http://datanucleus.org/documentation/problem_reporting.html#jdo Up to you to define what datasource(s) the test has. Clearly I'm not interested in any ISIS code, just the DN specific stuff ... persistable class, persistence code.
    bkalbfus
    @bkalbfus
    That's a start - do you have any tests I can look at for the FederatedStoreManager?
    Andy Jefferson
    @andyjefferson
    Nope. It's not part of the codebase that has ever been developed much beyond the basic persist handling. My tests aren't in public GitHub, just in private areas. Never got much interest from users so didnt go beyond what is there.
    bkalbfus
    @bkalbfus
    Glad to see the huge tests git repo now. I was looking at the unit tests inside the datanucleus-api-jdo repo and was thinking that can't be all of it! :)
    Andy Jefferson
    @andyjefferson
    @bkalbfus If you are doing queries on a FederatedStoreManager then be aware that the code simply goes via the primary datastore currently, as per https://github.com/datanucleus/datanucleus-core/blob/master/src/main/java/org/datanucleus/store/federation/FederatedStoreManager.java#L328 It has a JDOQL query string and would have to work out which datastore that query applies to, based on the candidate presumably, by splitting out the FROM clause and then doing a lookup of the appropriate store manager to query over. That then gets into unimplemented issues in Data Federation, see datanucleus-core plugin issues
    bkalbfus
    @bkalbfus
    I tried to do the least interruption in what is coded. The patch modifies the JDOQLTypedQueryImpl class, which knows what class it is handling. My patch adds code to determine which store manager to use via getStoreManagerForClass: https://github.com/datanucleus/datanucleus-core/blob/7641d12398238cfeb9076cb62969242565091401/src/main/java/org/datanucleus/store/federation/FederatedStoreManager.java#L220 .
    Andy Jefferson
    @andyjefferson
    JDOQLTypedQueryImpl is nothing to do with Federated datastores, hence not the place for such code. I don't see your "patch"
    bkalbfus
    @bkalbfus
    I was patching the version used by Apache Isis 2.0.0-M1. I forked the test repo you gave me the link to and demonstrated the problem: https://github.com/bkalbfus/test-jdo
    bkalbfus
    @bkalbfus
    The patch was posted on the Apache Isis issue - just to have a work-around available. I haven't successfully referenced my patched datanucleus-api-jdo from the test project to show it solving the issue.
    bkalbfus
    @bkalbfus
    bkalbfus
    @bkalbfus
    sorry for making the test too involved to see what was being tested at first glance. I removed the connection string assertions so that you can see the relevant assertion fail.
    bkalbfus
    @bkalbfus
    Is there a way to make use of a list of non-persistent objects as a parameter to a typesafe query? I'm trying to do something to the effect of SELECT * FROM myTable WHERE myTable.id IN (1,3,4,7,11,34,62)
    It is looking like calling query.listParameter("param") is for handling a list of peristent objects.
    Andy Jefferson
    @andyjefferson
    @bkalbfus Yes you can do "ListParameter.contains(field)" with a list of non-persistable objects - can require casting to avoid compiler whinges. No visibility of what you're actually doing so what problem you refer to. Obviously the code is open source so you can see that there is no dependency on persistable elements in the list
    bkalbfus
    @bkalbfus
    Thanks for pointing me in the right direction. I was able to get the code to compile by casting the listParameter. I set the parameter to an ArrayList, and the execution of the query results in this error:
    Cannot perform operation "==" on org.datanucleus.store.rdbms.sql.expression.ArrayLiteral@4d4633f7 and org.datanucleus.store.rdbms.sql.expression.NumericExpression@39614168 org.datanucleus.store.rdbms.sql.expression.IllegalExpressionOperationException: Cannot perform operation "==" on org.datanucleus.store.rdbms.sql.expression.ArrayLiteral@4d4633f7 and org.datanucleus.store.rdbms.sql.expression.NumericExpression@39614168 at org.datanucleus.store.rdbms.sql.expression.SQLExpression.eq(SQLExpression.java:381) at org.datanucleus.store.rdbms.sql.expression.ArrayExpression.eq(ArrayExpression.java:80) at org.datanucleus.store.rdbms.sql.method.CollectionContainsMethod.getExpression(CollectionContainsMethod.java:154) at org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory.invokeMethod(SQLExpressionFactory.java:433) at org.datanucleus.store.rdbms.sql.expression.CollectionExpression.invoke(CollectionExpression.java:54) at org.datanucleus.store.rdbms.sql.expression.CollectionLiteral.invoke(CollectionLiteral.java:153) at org.datanucleus.store.rdbms.query.QueryToSQLMapper.processInvokeExpression(QueryToSQLMapper.java:4410) at org.datanucleus.store.rdbms.query.QueryToSQLMapper.processInvokeExpression(QueryToSQLMapper.java:4264) at org.datanucleus.query.expression.AbstractExpressionEvaluator.compilePrimaryExpression(AbstractExpressionEvaluator.java:203) at org.datanucleus.query.expression.AbstractExpressionEvaluator.compileUnaryExpression(AbstractExpressionEvaluator.java:172) at org.datanucleus.query.expression.AbstractExpressionEvaluator.compileAdditiveMultiplicativeExpression(AbstractExpressionEvaluator.java:151) at org.datanucleus.query.expression.AbstractExpressionEvaluator.compileRelationalExpression(AbstractExpressionEvaluator.java:126) at org.datanucleus.query.expression.AbstractExpressionEvaluator.compileOrAndExpression(AbstractExpressionEvaluator.java:68) at org.datanucleus.query.expression.AbstractExpressionEvaluator.evaluate(AbstractExpressionEvaluator.java:36) at org.datanucleus.query.expression.Expression.evaluate(Expression.java:338) at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:72) at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileFilter(QueryToSQLMapper.java:591) at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compile(QueryToSQLMapper.java:467) at org.datanucleus.store.rdbms.query.JDOQLQuery.compileQueryFull(JDOQLQuery.java:911) at org.datanucleus.store.rdbms.query.JDOQLQuery.compileInternal(JDOQLQuery.java:364) at org.datanucleus.store.query.Query.executeQuery(Query.java:1928) at org.datanucleus.store.query.Query.executeWithMap(Query.java:1874) at org.datanucleus.api.jdo.query.JDOQLTypedQueryImpl.executeInternalQuery(JDOQLTypedQueryImpl.java:1141) at org.datanucleus.api.jdo.query.JDOQLTypedQueryImpl.executeList(JDOQLTypedQueryImpl.java:1036)
    bkalbfus
    @bkalbfus
    the code I used amounts to:
    long[] processedIds = ....;
    query.filter( ((ListExpression<List<Number>, Number> ) query.listParameter("processed ids")).contains(cand.id));
    query.setParameter("processed ids", Arrays.asList(processedIds)).executeList();
    bkalbfus
    @bkalbfus
    When I put a test into my test project, it works like expected. I'm thinking it may have to do with the branch of execution it is running in the CollectionContainsMethod class.
    bkalbfus
    @bkalbfus
    I found that setting the parameter to an array of the primitive int or long data type causes the error. I have the error condition primed in my test project at https://github.com/bkalbfus/test-jdo/blob/33f2dd94cf4051258de2d05e2eb52b35d30f8aa0/src/test/java/org/datanucleus/test/ArrayParamTest.java#L62
    bkalbfus
    @bkalbfus
    A related question: how do I represent a NOT IN filter?
    SELECT * FROM myTable where myTable.id NOT IN (1, 3, 6, 12, 33)
    My first hunch was to negate the BooleanExpression from the contains filter. That gave me an error:
    java.lang.UnsupportedOperationException: Dont currently support operator - in JDOQL conversion
        at org.datanucleus.api.jdo.query.AbstractJDOQLTypedQuery.getJDOQLForExpression(AbstractJDOQLTypedQuery.java:519)
    Andy Jefferson
    @andyjefferson
    Please dont use SQL equivalents, this is JDOQL which has its own (string) syntax using Java syntax; the sooner you adapt to that the better - quoting the string JDOQL form would be a way better way to proceed. As already said, you can use "contains", and so if you want to negate that you call "not()" on the contains expression. Works for me, and in the same way I can create a parameter of type List with Integer elements and that works for me too. If it doesn't for you then you need to debug your usage, and get the DN code.
    Andy Jefferson
    @andyjefferson
    Calling Arrays.asList() and passing in an int[] creates a List of int[] elements. Perhaps you don't mean to do that. #usererror
    bkalbfus
    @bkalbfus
    I would call such behavior in Arrays.asList a bug. That or a big violation of sense! Won't be the first. Thanks for the tip!
    bkalbfus
    @bkalbfus
    Using the JDOQLTypedQuery, I appended .neg() to the contains filter and got the error I quoted above. Test project is updated, please see here
    I assume that calling .neg on a BooleanExpression would be equivalent to wrapping the JDOQL boolean expression in not()
    bkalbfus
    @bkalbfus
    all good now. My code completion tool didn't give me the .not() method when I looked at first, so I guessed that .neg() was what I was looking for. Thanks! #usererror
    Steve Springett
    @stevespringett

    I’ve run into a blocking issue when attempting to upgrade from 5.1.9 to 5.2.0 and have narrowed it down to a change that was made between 5.1.9 and 5.1.10. So upgrading from 5.1.9 to 5.1.10 also does not work. Specifically I use http://www.datanucleus.org/products/accessplatform/jdo/mapping.html#valuegen_uuid and it appears that it doesn’t properly work with this change datanucleus/datanucleus-rdbms@7c75854 - at least that’s what appears to be happening - debugging DN can be challenging when you’re not familiar with the inner-workings.

    All along my UUID classes have used the following format:

    @Persistent(customValueStrategy = "uuid")
    @Unique(name = "TEAM_UUID_IDX")
    @Column(name = "UUID", jdbcType = "VARCHAR", length = 36, allowsNull = "false")
    @NotNull
    private UUID uuid;

    However, I have also tried the following with the same result

    @Persistent(customValueStrategy = "uuid-object")
    private UUID uuid;

    A NPE is thrown in both cases.

    java.lang.NullPointerException
        at org.datanucleus.store.rdbms.mapping.java.UUIDMapping.setObject(UUIDMapping.java:141)
        at org.datanucleus.store.rdbms.sql.SQLStatementHelper.applyParametersToStatement(SQLStatementHelper.java:310)
        at org.datanucleus.store.rdbms.query.JDOQLQuery.performExecute(JDOQLQuery.java:623)
        at org.datanucleus.store.query.Query.executeQuery(Query.java:1967)
        at org.datanucleus.store.query.Query.executeWithArray(Query.java:1856)
        at org.datanucleus.api.jdo.JDOQuery.executeInternal(JDOQuery.java:433)
        at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:276)
        at alpine.persistence.AbstractAlpineQueryManager.getObjectByUuid(AbstractAlpineQueryManager.java:518)

    Am I doing something wrong? Are there any working unit tests for this? I could only spot a single unit test in the rdbms module, so i assume if tests exist they are in another module. I need a 36 character UUID object for these fields and currently haven’t been able to achieve that with 5.1.10 and higher. Any pointers much appreciated.

    Andy Jefferson
    @andyjefferson
    The normal thing to do with an NPE is work out WHAT is null, and then you can understand why, what situation (of yours) is not catered for, and what fix to contribute. That change is amply documented (IMHO) in the issue tracker, and yes I have a test that it fixes. Clearly I don't have tests for your situations, but then that is why people have been advised to contribute to this project since 2003.
    Andy Jefferson
    @andyjefferson
    You only need to look at one class to debug the code ... UUIDMapping. UUID value generation tests are in jdo/identity as well as basic UUID tests in jdo/general, as well as my own tests (private).
    Steve Springett
    @stevespringett
    Well, seeing what’s null is easy. https://github.com/datanucleus/datanucleus-rdbms/blob/master/src/main/java/org/datanucleus/store/rdbms/mapping/java/UUIDMapping.java#L141 getColumn() is assumed to be not null, but in 5.1.10 and higher it is. I have no idea what it would be null, but will try to dig in and compare to 5.1.9.
    Steve Springett
    @stevespringett
    This is all new code introduced in 5.1.10 which seems to be a regression of sorts
    Steve Springett
    @stevespringett
    FYI, I added a test case demonstrating the issue, and a PR to fix it.
    rickz21
    @rickz21
    Hello, is this still active?
    Andy Jefferson
    @andyjefferson
    You mean the chat?
    rickz21
    @rickz21
    Hello Andy, I have a question about my code. Should I ask here? Or at https://stackoverflow.com/questions/tagged/jdo
    Andy Jefferson
    @andyjefferson
    Where support is provided is defined in http://www.datanucleus.org/support.html
    rickz21
    @rickz21

    I am using JDO v3.2 MySQL v5.1 and Datanucleus v5.2.
    in my PersistenceCapable class named Message I have a field named displayName.
    I want to make a list of all Messages written by people in group1.
    The following code works.

        Query<Message> q = pm.newQuery(myDomain.Message.class);
        Collection<Message> collection = (Collection<Message>) q.execute();
        messageCollection = pm.detachCopyAll(collection);
        q.closeAll();
        tx.commit();
        //...
        Set<String> names = MyUtility.getNames(group1);
        List<Message> messageList = new ArrayList<Message>();
        if (messageCollection != null) {
            for (Message message : messageCollection) {
                if (names.contains(message.getDisplayName())) {
                    messageList.add(message);
                }
            }
            Collections.sort(messageList, new MessageComparator());
        }

    I wanted to find a better way. I tried using Implicit Parameter and Collection Method.
    Query<Message> q = pm.newQuery("select from myDomain.Message where :names.contains(displayName)");
    But, that syntax doesn't work(JDOUserException).

    Andy Jefferson
    @andyjefferson
    Post Message and the rest of that query like where you define 'names'
    rickz21
    @rickz21

    Andy, thank you for your support.
    Your response reassured me that my code should have worked. I found my mistake.
    Here is what you requested.

    @PersistenceCapable(detachable = "true", table = "message")
    @DatastoreIdentity(strategy = IdGeneratorStrategy.IDENTITY)
    @Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
    public class Message {
        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        protected Long messageId = null;
        @Persistent
        @Column(name = "displayName", jdbcType = "VARCHAR", length = 20)
        private String displayName = null;
        @Persistent
        @Column(name = "inputText", jdbcType = "VARCHAR", length = 1200)
        private String inputText = "";
        public Message() {}
        public Message(String displayName, String inputText) {
            this.displayName = displayName;
            this.inputText = inputText;
        }
    //... setters and getters here
        @Override
        public String toString() {
            return "messageId is " + getMessageId();
        }
        public boolean equals(Message other) {
            return this.messageId == other.messageId;
        }
        public int hashCode() {
            return this.messageId.intValue();
        }
    }

    and

        Query<Entry> q = pm.newQuery("select from myDomain.Message where :names.contains(displayName)");
        q.declareParameters("java.util.Set names");
        Collection<Message> collection = (Collection<Message>) q.execute(names);

    which gave me
    javax.jdo.JDOUserException: Explicit parameters defined for query, yet implicit parameter syntax (":names") found
    As you probably already know, if I remove
    q.declareParameters("java.util.Set names");
    then the exception goes away.
    Now, I am using

        tx.begin();
        Query<Message> q = pm.newQuery("select from myDomain.Message where :names.contains(displayName)");
        Collection<Message> collection = (Collection<Message>) q.execute(names);
        messageCollection = (Collection<Message>)pm.detachCopyAll(collection);
        q.closeAll();
        tx.commit();

    Thanks again.

    nope-nope
    @nope-nope
    Hello everyone, I've got a question regarding JDO: what happens when you have 2 instances of the same data object (same id) but different reference and you edit them concurrently, and then reattach them? Are the changes to the object merged or are they overwritten by the last saved object? Thank you.
    Andy Jefferson
    @andyjefferson
    If the 2 instances of the same object are in detached state, then attaching will overwrite what was there, so whichever was the second attach overwrites the first attach. The detached object isn't to know what was done to the object in the intervening period, since it's detached. Clearly that depends if you have optimistic locking enabled or not, or exactly how you do the update ... in the same PM or not ... without code it is impossible to comment further. Just try it.
    nope-nope
    @nope-nope
    thank you Andy, I really appreciate your feedback. I'll continue testing - I think that requirement is a design/architecture problem