greptilian logo

IRC log for #javaee, 2014-01-21

Please see http://irclog.greptilian.com/javaee for which days have been logged.

| Channels | #javaee index | Today | | Search | Google Search | Plain-Text | plain, newest first | summary

All times shown according to UTC.

Time S Nick Message
01:51 jieryn joined ##javaee
01:51 jieryn joined ##javaee
02:21 firebird1 joined ##javaee
03:17 mocrunsthecity joined ##javaee
04:10 firebird1 joined ##javaee
04:15 firebird1 joined ##javaee
05:01 Quest- joined ##javaee
06:28 kotten joined ##javaee
07:43 kotten joined ##javaee
07:47 neuro_sys joined ##javaee
07:54 neuro_sys joined ##javaee
08:31 weyer joined ##javaee
08:36 fabioportieri joined ##javaee
08:45 weyer joined ##javaee
10:05 weyer joined ##javaee
10:27 sajjadg joined ##javaee
11:02 neuro_sys What's your opinion about the anemic domain model?
11:02 neuro_sys http://en.wikipedia.org/wiki/Anemic_domain_model
11:03 neuro_sys ™ Martin Fowler
11:04 weyer joined ##javaee
11:07 fabioportieri if you can avoid it, you should, i guess
11:09 fabioportieri it seems easy to avoid just use another object instead of trasforming the object itself
11:11 fabioportieri if i got it right
11:14 neuro_sys anemic domain model, is where the bean doesn't have any bussiness logic methods.
11:14 neuro_sys so models are POJOs with no methods
11:14 fabioportieri seems legit so far
12:39 BooleanByte joined ##javaee
13:30 icbytes joined ##javaee
13:30 icbytes hello. Am i right in here to ask about JNI ?
13:43 fabioportieri feel free to ask
13:45 fabioportieri joined ##javaee
13:53 icbytes i need to improve performance of an android app. ( So I could be wrong in here, but those from android-dev had no clue ).
13:56 fabioportieri try to paste some code icbytes
14:14 mocrunsthecity joined ##javaee
14:17 Naros joined ##javaee
15:32 sfisque joined ##javaee
16:38 Quest- joined ##javaee
16:56 neuro_sys joined ##javaee
16:56 neuro_sys joined ##javaee
17:03 Quest- left ##javaee
17:03 syncsys joined ##javaee
17:03 syncsys any help for http://stackoverflow.com/questions/21264352/non-optimized-regex-and-substr-with-injected-list-in-mysql-query
17:04 whartung that's a table scan.
17:06 whartung I assume substr(phone, -10) is the LAST 10 characters of the phone field?
17:07 whartung the better way to do that would be
17:07 whartung substr(phone, -10) IN ('3134548664', '117', '114,3224572751', '115','3455353536', '3007272543', …
17:07 whartung but it would still be table scan
17:07 syncsys hm.. and?
17:08 whartung the substr is killing you, you can't index that (unless mysql offer functional indexes)
17:08 whartung then the regexp is also killing you (the IN clause fixes that)
17:09 whartung so, it just gives up and tables scans…checking every row
17:09 ibaca joined ##javaee
17:11 syncsys yes. substr(phone, -10) is the LAST 10 characters of the phone field
17:11 syncsys hm
17:11 syncsys any other way?
17:11 syncsys how did the contactList became to be '3134548664', '117', '114,3224572751', '115','3455353536', '3007272543', …
17:11 whartung because that's what an IN clause wants
17:11 whartung you have a regex
17:12 whartung you need to either create a functional index (again, if mysql supports that), or you need to get rid of the substr(phone, -10)
17:12 whartung "I'll take 'Reasons to normalize data we query on for $100, Alex'"
17:13 syncsys can you tell in simple words that what this query does?
17:13 syncsys $100, Alex'"?
17:14 whartung it take the phone column (and the email column), then it takes the right most 10 characters, then it checks if that value is in the list of values represented by the regex.
17:14 whartung the OR is also killing thos.
17:14 whartung this
17:14 whartung it's a game show reference for Jeopardy
17:15 mocrunsthecity joined ##javaee
17:15 whartung whoever stored this data should have either a) cleaned up the phone column originally, or created a parallel, normalized, cleaned up version of it at the same time. Then you could have done, simply:
17:15 syncsys hm
17:15 whartung phone in ['111','222','333'…]
17:15 whartung actually that's ('111'...)
17:15 whartung and that would have used an index placed on the phone column
17:16 whartung as it is now, that can't happen. The regex, the substr, and the OR all conspire to make this a table scan
17:16 whartung so, 20m rows…each and every time.
17:17 syncsys ok. I think I can cease to use the last 10 digits and use the full phone digit length. will that help?
17:18 whartung that will help. in that case you should put an index on the phone column, then an index on the email column (same logic applies here), convert the regex list in to the IN clause: phone in ('…',…), and then change the OR to a UNION.
17:19 whartung SELECT….FROM… WHERE phone IN (…) UNION SELECT … FROM … WHERE email IN (…)
17:19 whartung that query should use both indexes
17:19 whartung the only difference is that if there was a chance for duplicate rows in the first query, that won't happen in the second, and UNION removes duplicates. -- this is likely not an issue.
17:20 whartung but , be aware of the difference.
17:20 whartung try typing that in to you SQL listener see if it's any faster
17:21 syncsys hm
17:21 syncsys nice
17:25 syncsys will try it
17:44 syncsys in hibernate. what would @Transactional(readOnly = false) mean and I have seen @Transactional(readOnly = true) at class declaration while in the same class @Transactional(readOnly = false) at top of method declaration. why is that?
17:45 whartung by default, readOnly = false, so it's not actually necessary.
17:46 syncsys sure?
17:46 whartung yup
17:46 syncsys hm. so whats the point in making @Transactional(readOnly = true) at class declaration while in the same class @Transactional(readOnly = false) at top of method declaration.
17:47 whartung at the class level, it makes readOnly= true default for the methods. In this case, the =false exempts a specific method(s)
17:47 sheenobu joined ##javaee
17:48 syncsys hm.. so all method become true, while the explicit stated as false , override the true
17:48 whartung yes
17:48 syncsys readOnly = true is just that it wont let the data to change. just view. right
17:49 whartung correct -- since it "knows" the dat won't change, the underlying entity manager won't stand up the extra data needed to track changes and such
17:49 syncsys right
17:49 whartung now, I can't say what the difference is between a read-only entity and an unmanaged entity.
17:50 syncsys so for getSomethingByIdOrName, making it @Transactional(readOnly = true)     or if the class declares true, declare nothing on top of method)  would be nicer?
17:52 syncsys am. well I got the point
18:12 [1]BooleanByte joined ##javaee
18:17 sajjadg joined ##javaee
18:20 [1]BooleanByte joined ##javaee
19:29 syncsys http://pastie.org/8654704#4-6 the highlighted lines looks fishy, the priority is being set and get in the same transactional method. I think hibernate would only communicate with the DB just once at the end. it wont first setPriority, come back , getPriority , compare. ?
19:32 whartung sure it'll set priority
19:32 whartung it just won't talk to the db until a query is made or the transaction is committed
19:33 syncsys when the transaction is commited?
19:34 whartung yea
19:35 syncsys I mean ,when the transaction is commited?
19:36 whartung the transaction is committed when the method that starts the transaction is exited.
19:36 whartung so, in this case, changeTaskPriority will commit after the "return result" happens.
19:36 syncsys hm
19:37 whartung but if changeTaskPriority is called from another @Transactional method, then it'll commit when that first method exits
19:37 whartung (unless an exception is thrown, then the transaction will get rolled back)
19:37 whartung but that general guidelines ,I can't speak to the specifics of the @Transaction annotation in this case.
19:38 syncsys hm
19:55 syncsys whartung,  http://pastie.org/8654787#3-4,17,32
19:57 whartung what is this syncsys
19:58 syncsys splitted the getPriority / getTask and setPriority into 2 transactional methods.
19:59 whartung ok
19:59 syncsys looks better?
20:00 whartung you really don't need to wrap the setters of an entity in a Transactional. Rather you should wrap the overarching business methods in a @Transcational
20:00 whartung afk bbl
20:01 syncsys thanks!
20:06 syncsys whartung,  http://pastie.org/8654814#3,6,9,13-17,29,43
20:31 sfisque well no methods on an entity should be Tx-able, entities have no EM injection and have no Tx context other than the enclosing Tx that holds them.
20:31 syncsys Tx?
20:31 sfisque transaction
20:32 sfisque no methods on an entity should be annotated Transactional.  it's an anti-pattern and can cause havoc
20:32 sfisque because multiple Tx's can be acting on the same object in a concurrent system
20:32 syncsys wo.. I had issues if i didnt annotated
20:33 syncsys the method annotations would override the annotation on its class
20:33 syncsys so no issues i gues
20:33 sfisque are you sure?  i'm guessing you had Tx annotations on your DAO, which is proper.  the entity should be considered just a payload object
20:33 syncsys yup, without @transactional and @ service, t dont work
20:33 syncsys no. those are service methods
20:33 syncsys in service class
20:33 sfisque right
20:34 sfisque you WANT those Tx-able
20:34 syncsys hm
20:34 sfisque the entity should be Tx agnostic
20:34 syncsys I do, how ever, want @repository in DAOs,
20:34 syncsys I dont know why its mandatary, though i heard that it works without it too
20:35 sfisque that must be a spring anno.  i'm not aware of such an anno
20:35 syncsys sfisque,  any way, any comments about http://pastie.org/8654814#3,6,9,13-17,29,43 or the depricated at bottom?
20:35 syncsys ok
20:36 sfisque why are you making a mutator Tx-able?  it's not committing anything to the repo.
20:36 sfisque @Deprecated is the proper spelling
20:37 sfisque remove public Tasks setTaskPriority.  it's a meaningless indirection
20:37 sfisque you can just call the mutator on the entity
20:37 sfisque no need ot wrap an Tx there, and it's unnecessary indirection.  you get nothing but losing a few clock cycles
20:38 sfisque the only reason to do somethign like that is if you're going to immediately commit the change OR you're using a "guarded object" pattern for security
20:39 syncsys but if i am in the same transactional method, it wont got back to DB and set the priority
20:39 syncsys <whartung> it just won't talk to the db until a query is made or the transaction is committed
20:39 syncsys <whartung> the transaction is committed when the method that starts the transaction is exited.
20:39 syncsys <whartung> so, in this case, changeTaskPriority will commit after the "return result" happens.
20:39 syncsys <whartung> but if changeTaskPriority is called from another @Transactional method, then it'll commit when that first method exits
20:40 sfisque only if the entity is managed.  if it's detached, nothing will happen, even if you commit
20:40 syncsys old details: http://pastie.org/8654704#4-6 the highlighted lines looks fishy, the priority is being set and get in the same transactional method. I think hibernate would only communicate with the DB just once at the end. it wont first setPriority, come back , getPriority , compare. ?
20:41 sfisque depends.  the ORM is free to do fetches if it detects that a managed object is stale
20:41 sfisque or is anemic and needs fluffing
20:42 syncsys the entity wouuld ofcourse be managed
20:43 sfisque do not say of course.  if it's being round tripped from the UI and was being held in a session scoped object, it's going to be detached
20:45 syncsys hm
20:46 syncsys Getting different advices from equally reputed persons. I am confused :)|
20:46 syncsys I had been to #hibernate too.
20:47 syncsys different point of views
20:47 syncsys all gave different point of views
20:47 syncsys and all sounded promising. including you
20:56 Naros left ##javaee
21:12 sfisque that's the nature of software.  million ways to skin the cat.
21:19 syncsys hm
21:19 whartung sfisque is mistaken, only what I say is right.
21:19 * sfisque bonks whartung on the head
21:20 syncsys :)
21:20 syncsys whartung,  so what are your views for
21:21 syncsys http://pastie.org/8654814#3,6,9,13-17,29,43 or the depricated at bottom?
21:21 whartung I'd just do the bottom one.
21:22 syncsys really?
21:22 whartung yes
21:22 syncsys but it wont let us know wheather it updated in the db or not (untill we get out of the method)
21:22 syncsys http://pastie.org/8654704#4-6 the highlighted lines looks fishy, the priority is being set and get in the same transactional method. I think hibernate would only communicate with the DB just once at the end. it wont first setPriority, come back , getPriority , compare. ?
21:23 whartung because the bottom one is a business method. "I want to change the priority of task ID #xxx". You, as the user of such a method, aren't exposed to how that is actually done.
21:23 whartung so it's a good service method
21:23 whartung no, it won't.
21:24 whartung hibernate fetched the entity when you did the find
21:24 sfisque doesnt hibernate use anemic proxies?
21:24 sfisque or is that something JPA lays over top?
21:24 sfisque it's been a while since i used hibernate natively
21:24 whartung if hibernate doesn't have the value of priority at that point, you need to reconfigure it -- because that's stupid.
21:25 whartung nobody lazy loads the scalar fields -- that's completely insane
21:27 sfisque actually it would HAVE to proxy the entity, so it can intercept mutators to register dirtiness
21:28 sfisque i would assume the proxy only contains a PK reference and maybe a ref to the @Version attribute
21:28 syncsys hibernate fetched the entity when you did the find, but then I did a task.setProperty(). now in the same method, a few lines ahead, how would I know that the taskPriority has been changed/set while the transaction had not been committed yet?
21:28 sfisque and then passes calls through once the underlying object is fluffed
21:28 syncsys whartung,  ^
21:29 whartung of course it proxies the entity but it populated the entity when it did the find.
21:29 sfisque syncsys this is what @Version is for
21:29 sfisque Optimistic locking
21:29 sfisque Tx goes to commit and detects the entity is stale because @Version is one or more behind what the actual value in the repo is
21:29 whartung when you do entity = em.find()… the entity you get back is not a shell. It's all wrapped up with interceptors and crap, but it's not a shell.
21:30 whartung it's collection references very well might be with LAZY fetching, but the basic scalars aren't
21:30 syncsys ok but  in the same method, a few lines ahead, how would I know that the taskPriority has been changed/set while the transaction had not been committed yet?
21:30 sfisque by shell you mean anemic?  because it is a "shell" wrapped around the entity (java.lang.reflect.Proxy)
21:31 sfisque if you mean anemic, then might agree, but i think that is impl specific from a jpa standpoint (aka, the impl can decide how to do it )
21:31 * syncsys snores
21:32 whartung well since proxies only work with interfaces, it's a normal java class that's been bombarded with shenanigan rays to inject the intercepts etc.
21:32 whartung any jpa implementation that makes: entity = em.find(..); x = entity.getScalar(); in to 2 DB calls deserves to be destroyed. Absolute insanity
21:35 whartung I don't know what you mean syncsys
21:35 syncsys ok but  in the same method, a few lines ahead, how would I know that the taskPriority has been changed/set while the transaction had not been committed yet?
21:35 syncsys whartung,  oh.
21:35 syncsys a minut
21:37 syncsys http://pastie.org/8654704#4-6 line 3 gets task, line 4 changes the priority, on line 6, the POJO is been evaluated and we dont know that if its (priority) being changed and reflected in the database.
21:39 syncsys whartung,  have I made a valid point
21:43 whartung nothing is reflected in thte db until JPA flushes to it.
21:43 whartung JPA flushes to the DB at 3 points
21:43 whartung 1) when a transaction commits
21:43 whartung 2) when you tell it to explicitly flush
21:43 whartung 3) when you do a query against the db
21:43 whartung 99% of the time, you don't care
21:44 whartung but if you did something like this
21:44 whartung Thing t = em.find(Thing.class, 1);
21:44 whartung t.setValue("myValue");
21:44 semiosis what if you have many app instances connected to the db?
21:44 whartung List<Thing> things = findThingsWithValue("myValue");
21:45 whartung that list of Things will have your just changed entity in
21:45 whartung if you want to talk about generic SQL transaction semantics, then we can talk about that -- but that's orthogonal to how JPA treats the DB
21:47 syncsys ya , i got it. nice elaboration.
21:47 syncsys but
21:47 syncsys what if I want to know : wheather my made change was saved or not.
21:48 syncsys _in the middle of a method_
21:48 whartung Why do you care?
21:48 whartung why does the method care?
21:48 syncsys do be sure that the priority WAS changed before I just return succes.....
21:48 whartung this happened 2ms ago
21:48 whartung if it WASN'T saved, you get a nice nasty exception
21:49 syncsys yes. 2ms, but it MIGHT be a failure too.
21:49 whartung and everything goes to hell
21:49 syncsys what kind of exception?
21:49 whartung disk full
21:49 whartung out of memory
21:49 syncsys i never handled exceptions
21:49 whartung CRC error
21:49 whartung sig fault
21:49 whartung who knows
21:50 syncsys oh, so I should handle such things in exceptions?
21:50 whartung here's the deal
21:50 whartung if the problem is a BUSINESS rule, you should enforce it in your code.
21:50 whartung for example
21:50 whartung you can have a NOT NULL constraint on a column in the DB
21:50 syncsys hm
21:50 whartung your code should ALSO enforce that.
21:50 syncsys hm
21:50 whartung you don't rely on the DB for validation. That's last resort
21:50 whartung the reason why is partly what you're encountering here.
21:51 syncsys what kind of exception handling you might want to have in that method?
21:52 syncsys there are not checked exceptions for  entityManager.find .merge etc
21:52 syncsys there are no checked exceptions for  entityManager.find .merge etc
21:52 syncsys 8
21:55 whartung by the time you find out you got the exception, from the database, it's typically "too late"
21:56 whartung even worse, on some databases notably postgres, a single exception from the DB ruins the entire transaction
21:56 whartung but consider
21:57 whartung public void addThing(Thing t) {
21:57 whartung if (t.getValue() == null) { throw new IllegalArgumentException("Things must have values."); }
21:57 whartung because you KNOW (as a business rule) that the DB won't allow you to persist a Thing with a null Value.
21:58 whartung afk bbl
22:02 syncsys thanks
22:04 Sebboh joined ##javaee
22:57 kotten joined ##javaee
23:43 Naros joined ##javaee
23:49 Naros left ##javaee

| Channels | #javaee index | Today | | Search | Google Search | Plain-Text | plain, newest first | summary

Please see http://irclog.greptilian.com/javaee for which days have been logged.