Match #1: /using_scroll.java: line 1-19 /java/5713059-5713930-1: line 3-21 //Do your + insertions via Hibernate via batch updates technique. Session session = sessionFactory.openSession(); >Transaction tx = session.beginTransaction(); > >ScrollableResults customers = session.getNamedQuery("GetCustomers") > .setCacheMode(CacheMode.IGNORE) > .scroll(ScrollMode.FORWARD_ONLY); >int count=0; >while ( customers.next() ) { > Customer customer = (Customer) customers.get(0); > customer.updateStuff(...); > if ( ++count % 20 == 0 ) { > //flush a batch of updates and release memory: > session.flush(); > session.clear(); > } >} > >tx.commit(); >session.close(); Match #2: /flush_and_clear_session.java: line 1-15 /java/2876888-2877589-1: line 3-19 //Making new objects persistent flush() and then clear() the session regularly in order to control the size of the first-level cache. Session session = sessionFactory.openSession(); >Transaction tx = session.beginTransaction(); >for ( int i=0; i<100000; i++ ) { >Customer customer = new Customer(.....); > session.save(customer); > > if ( i % 20 == 0 ) { //20, same as the JDBC batch size > > //flush a batch of inserts and release memory: > > session.flush(); > > session.clear(); > } >} >tx.commit(); >session.close(); Match #3: /using_a_StatelessSession.java: line 1-13 /java/2761543-2761630-1: line 3-15 //Operations performed using a stateless session never cascade to associated instances. Collections are ignored by a stateless session. Operations performed via a stateless session bypass Hibernate's event model and interceptors. A stateless session is a lower-level abstraction that is much closer to the underlying JDBC. StatelessSession session = sessionFactory.openStatelessSession(); >Transaction tx = session.beginTransaction(); > >ScrollableResults customers = session.getNamedQuery("GetCustomers") > .scroll(ScrollMode.FORWARD_ONLY); >while ( customers.next() ) { > Customer customer = (Customer) customers.get(0); > customer.updateStuff(...); > session.update(customer); >} > >tx.commit(); >session.close(); Match #4: /CriteriaQueryTest.java: line 666-679 /java/2801764-2801934-1: line 3-12 //You'll have to use a Hibernate : Transformers for HQL and SQL blog post gives the following example (where StudentDTO is a non-entity Bean). < List resultWithAliasedBean = s.createCriteria(Enrolment.class) < .createAlias("student", "st") < .createAlias("course", "co") < .setProjection( Projections.projectionList() < .add( Projections.property("st.name"), "studentName" ) < .add( Projections.property("co.description"), "courseDescription" ) < ) < .addOrder( Order.desc("studentName") ) < .setResultTransformer( Transformers.aliasToBean(StudentDTO.class) ) < .list(); < < assertEquals(2, resultWithAliasedBean.size()); < < StudentDTO dto = (StudentDTO) resultWithAliasedBean.get(0); --- >List resultWithAliasedBean = s.createCriteria(Enrolment.class) > .createAlias("student", "st").createAlias("course", "co") > .setProjection( Projections.projectionList() > .add( Projections.property("st.name"), "studentName" ) > .add( Projections.property("co.description"), "courseDescription" ) > ) > .setResultTransformer( Transformers.aliasToBean(StudentDTO.class) ) > .list(); > > StudentDTO dto = (StudentDTO)resultWithAliasedBean.get(0); Match #5: /SerializingCollection.java: line 95-98 /java/11653374-11654213-2: line 4-7 //Want to write an object to disk you need use something like this. < ByteArrayOutputStream baos = new ByteArrayOutputStream(); < ObjectOutputStream oos = new ObjectOutputStream(baos); < oos.writeObject(o); < byte[] buffer = baos.toByteArray(); --- >ByteArrayOutputStream baos = new ByteArrayOutputStream(); >ObjectOutputStream oos = new ObjectOutputStream(baos); >oos.writeObject(obj); >byte[] data = baos.toByteArray(); Match #6: /InstrumentedClassLoader.java: line 58-60 /java/5368704-5368731-1: line 4-10 // If you simply want to know how to append byte arrays, you simply create a new byte array that has a length equal to the sum of the sizes of the arrays you wish to append, then use System.arraycopy to move copy the original arrays. < byte[] temp = new byte[ originalClass.length + buffer.length ]; < System.arraycopy( originalClass, 0, temp, 0, originalClass.length ); < System.arraycopy( buffer, 0, temp, originalClass.length, buffer.length ); --- >byte[] destination = new byte[ciphertext.length + mac.length]; > >// copy ciphertext into start of destination (from pos 0, copy ciphertext.length bytes) >System.arraycopy(ciphertext, 0, destination, 0, ciphertext.length); > >// copy mac into end of destination (from pos ciphertext.length, copy mac.length bytes) >System.arraycopy(mac, 0, destination, ciphertext.length, mac.length); Match #7: /ByteCodeHelper.java: line 65-69 /java/5368704-5368731-1: line 4-10 // If you simply want to know how to append byte arrays, you simply create a new byte array that has a length equal to the sum of the sizes of the arrays you wish to append, then use System.arraycopy to move copy the original arrays. < byte[] temp = new byte[ classBytes.length + buffer.length ]; < // copy any previously read bytes into the temp array < System.arraycopy( classBytes, 0, temp, 0, classBytes.length ); < // copy the just read bytes into the temp array (after the previously read) < System.arraycopy( buffer, 0, temp, classBytes.length, buffer.length ); --- >byte[] destination = new byte[ciphertext.length + mac.length]; > >// copy ciphertext into start of destination (from pos 0, copy ciphertext.length bytes) >System.arraycopy(ciphertext, 0, destination, 0, ciphertext.length); > >// copy mac into end of destination (from pos ciphertext.length, copy mac.length bytes) >System.arraycopy(mac, 0, destination, ciphertext.length, mac.length); Match #8: /ArrayHelper.java: line 186-188 /java/4697255-4697284-1: line 3-5 //Combine integer arrays. System.arraycopy is a method you can use to perform this copy. < int[] result = new int[ x.length + y.length ]; < System.arraycopy( x, 0, result, 0, x.length ); < System.arraycopy( y, 0, result, x.length, y.length ); --- >int[] array1and2 = new int[array1.length + array2.length]; >System.arraycopy(array1, 0, array1and2, 0, array1.length); >System.arraycopy(array2, 0, array1and2, array1.length, array2.length); Match #9: /CacheRegionUtils.java: line 120-123 /java/5283444-5283753-1: line 3-6 //Convert array of strings into a string in Java. < StringBuilder sb = new StringBuilder(); < for ( String s : elements ) { < sb.append( s ).append( c ); < } --- >StringBuilder builder = new StringBuilder(); >for(String s : arr) { > builder.append(s); >} Match #10: /PersistentSet.java: line 117-122 /java/7445910-7445937-1: line 3-6 //The best way to iterate over a non-generic List. < Iterator iter = set.iterator(); < while ( iter.hasNext() ) { < Object test = iter.next(); < Object oldValue = sn.get(test); < if ( oldValue==null || elementType.isDirty( oldValue, test, getSession() ) ) return false; < } --- >Iterator iter = objects.iterator(); >while (iter.hasNext()) { > Object element = iter.next(); >} Match #11: /AnnotationBinder.java: line 782-785 /java/5283444-5283753-1: line 3-6 //Convert array of strings into a string in Java. < StringBuilder missings = new StringBuilder(); < for ( String property : missingIdProperties ) { < missings.append( property ).append( ", " ); < } --- >StringBuilder builder = new StringBuilder(); >for(String s : arr) { > builder.append(s); >}