Search Results

Search found 9 results on 1 pages for 'abovesun'.

Page 1/1 | 1 

  • again about JPA/Hibernate bulk(batch) insert

    - by abovesun
    Here is simple example I've created after reading several topics about jpa bulk inserts, I have 2 persistent objects User, and Site. One user could have many site, so we have one to many relations here. Suppose I want to create user and create/link several sites to user account. Here is how code looks like, considering my willing to use bulk insert for Site objects. User user = new User("John Doe"); user.getSites().add(new Site("google.com", user)); user.getSites().add(new Site("yahoo.com", user)); EntityTransaction tx = entityManager.getTransaction(); tx.begin(); entityManager.persist(user); tx.commit(); But when I run this code (I'm using hibernate as jpa implementation provider) I see following sql output: Hibernate: insert into User (id, name) values (null, ?) Hibernate: call identity() Hibernate: insert into Site (id, url, user_id) values (null, ?, ?) Hibernate: call identity() Hibernate: insert into Site (id, url, user_id) values (null, ?, ?) Hibernate: call identity() So, I means "real" bulk insert not works or I am confused? Here is source code for this example project, this is maven project so you have only download and run mvn install to check output.

    Read the article

  • RESTful services architecture question

    - by abovesun
    This is question more about service architecture strategy, we are building big web system based on rest services on back end. And we are currently trying to build some standard internal to follow while developing rest services. Some queries returns list of entities, for example lets consider we have image galleries retrieving service: /gell_all_galeries, returning next response: <galleries> <gallery> <id>some_gallery_id</id> <name>my photos</name> <photos> <photo> <id>123</id> <name>my photo</name> <location>http://mysite/photo/show/123</location> ...... <author> <id>some_id</id> <name>some name</name> ....... <author> </photo> <photo> ..... </photo> <photo> ..... </photo> <photo> ..... </photo> <photo> ..... </photo> </photos> </gallery> <gallery> .... </gallery> <gallery> .... </gallery> <gallery> .... </gallery> <gallery> .... </gallery> </galleries> As you see here, response quite big and heavy, and not always we need such deep info level. Usual solution is to use or http://ru.wikipedia.org/wiki/Atom elements for each gallery instead of full gallery data: <galleries> <gallery> <id>some_gallery_id</id> <link href="http://mysite/gallery/some_gallery_id"/> </gallery> <gallery> <id>second_gallery_id</id> <link href="http://mysite/gallery/second_gallery_id"/> </gallery> <gallery> .... </gallery> <gallery> .... </gallery> <gallery> .... </gallery> <gallery> .... </gallery> </galleries> The first question, is next: maybe instead we shouldn't even use and types, and just use generic and for all resources that return list objects: <list> <item><link href="http://mysite/gallery/some_gallery_id"/></item> <item><link href="http://mysite/gallery/other_gallery_id"/></item> <item>....</item> </list> And the second question, after user try to retrieve info about some concrete gallery, he'll use for example http://mysite/gallery/some_gallery_id link, what should he see as results? Should it be: <gallery> <id>some_gallery_id</id> <name>my photos</name> <photos> <photo> <id>123</id> <name>my photo</name> <location>http://mysite/photo/show/123</location> ...... <author> <id>some_id</id> <name>some name</name> ....... <author> </photo> <photo> ..... </photo> <photo> ..... </photo> <photo> ..... </photo> <photo> ..... </photo> </photos> </gallery> or : <gallery> <id>some_gallery_id</id> <name>my photos</name> <photos> <photo><link href="http://mysite/photo/11111"/></photo> <photo><link href="http://mysite/photo/22222"/></photo> <photo><link href="http://mysite/photo/33333"/> </photo> <photo> ..... </photo> </photos> </gallery> or <gallery> <id>some_gallery_id</id> <name>my photos</name> <photos> <photo> <link href="http://mysite/photo/11111"/> <author> <link href="http://mysite/author/11111"/> </author> </photo> <photo> <link href="http://mysite/photo/22222"/> <author> <link href="http://mysite/author/11111"/> </author> </photo> <photo> <link href="http://mysite/photo/33333"/> <author> <link href="http://mysite/author/11111"/> </author> </photo> <photo> ..... </photo> </photos> </gallery> I mean if we use link instead of full object info, how deep we should go there? Should I show an author inside photo and so on. Probably my question ambiguous, but what I'm trying to do is create general strategy in such cases for all team members to follow in future.

    Read the article

  • target="_top" emulation using JavaScript

    - by abovesun
    Suppose we have frameset of with 2 frames, one frame is kind a tiny horizontal header and second is kind of "content" frame with 3rd-party html page inside. When user clicks on some link inside "content" frame, the whole page (frameset) should be reloaded with this link, the same behavior if "content" frame has "target=_top" attribute. How to do this using JS?

    Read the article

  • Please suggest some alternative to Drupal

    - by abovesun
    Drupal propose completely different approach in web development (comparing with RoR like frameworks) and it is extremely good from development speed perspective. For example, it is quite easy to clone 90% of stackoverflow functionality using Drupal. But it has several big drawbacks: it is f''cking slow (100-400 requests per page) db structure very complicated, need at least 2 tables for easy content (entity) type, CCK fields very easy generate tons of new db tables anti-object oriented, rather aspect-oriented bad "view" layer implementation, no strange forward layouts and so on. After all this items I can say I like Drupal, but I would like something same, but more elegant and more object oriented. Probably something like http://drupy.net/ - drupal emulation on the top of django. P.S. I wrote this question not for new holy word flame, just write if you know alternative that uses something similar approach.

    Read the article

  • Authentication and authorization for RESTfull API (java jersery)

    - by abovesun
    Hi, implementing service something similar with tinyurl or bit.ly, I'm would like to expose service as API, I'm using java and jersey as RESTfull service implementation. I'm looking for simplest way for authentification of users who use API, OAuth is first thing coming in mind, but the problem is I don't need this 3 iteration calls with request token query, than access token query with callback url passing. I just need to give user ability to invoke api with no additional security calls to my server.

    Read the article

  • Strange befaviour of spring transaction support for JPA + Hibernate +@Transactional annotation

    - by abovesun
    I found out really strange behavior on relatively simple use case, probably I can't understand it because of not deep knowledges of spring @Transactional nature, but this is quite interesting. I have simple User dao that extends spring JpaDaoSupport class and contains standard save method: @Transactional public User save(User user) { getJpaTemplate().persist(user); return user; } If was working fine until I've add new method to same class: User getSuperUser(), this method should return user with isAdmin == true, and if there is no super user in db, method should create one. Thats how it was looking like: public User createSuperUser() { User admin = null; try { admin = (User) getJpaTemplate().execute(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { return em.createQuery("select u from UserImpl u where u.admin = true").getSingleResult(); } }); } catch (EmptyResultDataAccessException ex) { User admin = new User('login', 'password'); admin.setAdmin(true); save(admin); // THIS IS THE POINT WHERE STRANGE THING COMING OUT } return admin; } As you see code is strange forward and I was very confused when found out that no transaction was created and committed on invocation of save(admin) method and no new user wasn't actually created despite @Transactional annotation. In result we have situation: when save() method invokes from outside of UserDAO class - @Transactional annotation counted and user successfully created, but if save() invokes from inside of other method of the same dao class - @Transactional annotation ignored. Here how I was change save() method to force it always create transaction. public User save(User user) { getJpaTemplate().execute(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { em.getTransaction().begin(); em.persist(user); em.getTransaction().commit(); return null; } }); return user; } As you see I manually invoke begin and commit. Any ideas?

    Read the article

1