發表文章

目前顯示的是 11月, 2011的文章

JavaScript and memory leaks

http://www.javascriptkit.com/javatutors/closuresleak/index.shtml

Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.

In entity bean, the foreign key usually replaced by the referential relationship such as : public class Status implements Serializable {     /**      *      */     private static final long serialVersionUID = 1L;     @Column(name="creation_datetime", nullable = false)     private Timestamp creationDatetime;     @Id     @Column(name="seq_no", nullable = false)     @GeneratedValue(strategy=GenerationType.IDENTITY)     private Integer seqNo;     @Column(name="status", nullable = false)     private String status;     @Column(name="car_id", nullable = false, insertable=false, updatable=false)     private String carId;     @ManyToOne     @JoinColumn(name = "car_id")     private Transaction transaction;     public Status() {     }     public Status(Timestamp creation_datetime,                           Transaction transaction,                           Integer seqNo, String status, String carId) {         this.creationDatetime = creati

Servlet 3.0 Tutorial: @WebListener, @WebServlet, @WebFilter and @WebInitParam

http://blog.caucho.com/2009/10/06/servlet-30-tutorial-weblistener-webservlet-webfilter-and-webinitparam/

When should we close the EntityManager and EntityManagerFactory

For EntityManager: It depends on how you obtained it.  If you created it using EntityManagerFactory you will have to close it no matter what framework you use. If you obtained it using dependency injection (eg using EJB and @PersistenceContext annotation) you should not close it by hand. It's the EntityManager that is actually associated to a database connection and closing the EntityManager will actually release the JDBC connection (most often, return it to a pool). For EntityManagerFactory: Closing an EntityManagerFactory would be closer to destroying a whole connection pool. If you want to think JDBC connection, you should think EntityManager. We should not close the factory after every operation. Creating an EntityManagerFactoryis a pretty expensive operation and should be done once for the lifetime of the application (you close it at the end of the application). So, no, you should not close it for each persist/update/delete operation. The EntityManagerFa

JPA Caching

http://weblogs.java.net/blog/archive/2009/08/21/jpa-caching http://www.developer.com/java/ent/article.php/3892261/JPA-20-Cache-Vs-Hibernate-Cache-Differences-in-Approach.htm

ClassCastException of persistence.xml

java.lang.ClassCastException: : org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration" occurred while attempting to determine the version of "zip:C:/JDeveloper/11.1.1.4.0/user_projects/domains/.../persistence.xml". The problem maybe caused by the encoding of the persistence.xml. Another possible reason is caused by the classloading of the xercesImpl.jar. Qwblogic has built-in xercesImpl.jar, your application should load the jar from parent classloader. However,  using org.apache.xerces.* in weblogic-application.xml may cause classloading problem.  Solution: Remove the prefer settings from weblogic-application.xml - not exactly work or exclude this jar from POM.xml. - work

ClassCastException of entity class

The problem maybe caused by the entity class has been cached in the server even you have renamed the package and redeploy the application. For example, com.service.persistence.delivery.A changed to com.service.persistence.reprint.delivery.A. private static String persistenceUnitName = "EclipseLinkWeb"; private static EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName); EntityManagerFactory is acquired statically, and there is no code to free the EntityManagerFactory and other resources before the app starts up again.  This causes the underlying resources to still exist, which have links to the old classloader, and this leads to java.lang.ClassCastException after redeployment. Workaround: Please restart the server. Solution: First, I added the following method to JPAUtil class: public class JPAUtil {   ...       public static void releaseResources() {         if (emf != null) {             emf.close();         }            }

Solution: Can't delete "The... folder does not exist. The file may have been moved or deleted."

Use RMDIR on containing folder Begin like the previous method, but try also rmdir /s foldername (replace foldername with the name of the folder to be deleted). This command should delete a folder with all its subfolders. If the folder name contains one or more spaces, enclose it in quotes. Example: rmdir /s " folder name " Note that the abbreviated command rd can be used in place of rmdir.

Grant right to user to run update statistics on SQL server

create procedure dbo . up_updstats with execute as 'dbo' as exec sp_updatestats go grant execute on dbo . up_updstats to [ ] go

View raw HTTP request on SoapUI

After you sent the soap message to web service end point, please click HTTP log at the bottom of the screen to view the whole HTTP request.

Access web service with username token by SoapUI

Create a new project on SoapUI. Double click on the Binding item. Select Service Endpoint tab page on the property window. Provide username, password. Select PasswordText as the WSS-Type.

Programmatic EntityManager

Instead of you dependence Injection for EntityManager by annotation, you can also adopt programmatic EntityManager by the following code. private static EntityManagerFactoryMap buildEmFactories(String name, String persistenceUnit){                 List dsList =  CsvConfigManager.getReprintConfig(name).getDataSourceList();         EntityManagerFactoryMap managerFactories = new EntityManagerFactoryMap();         for (DataSourceEntry ds: dsList) {             HashMap property = new HashMap ();             property.put(TRANSACTION_TYPE, "JTA");             property.put(JTA_DATASOURCE, ds.getJndi());             property.put(CACHE_TYPE_DEFAULT, "NONE");             property.put(CACHE_SHARED_DEFAULT, "false");             property.put(WEAVING_INTERNAL, "false");             property.put(SESSION_NAME, ds.getJndi());             property.put(LOGGING_SESSION, "false");             property.put(CATEGORY_LOGGING_LEVEL_, "WARNING");

MS SQL Server: EXECUTE permission denied on xp_sqljdbc_xa_init_ex

When attempting to start the system using MS SQL Server 2008 R2 you get an exception like: javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc_SQLServerException: failed to create the XA control connection. Error: "The EXECUTE permission was denied on the object 'xp_sqljdbc_xa_init_ex', database 'master' schema 'dbo' To fix the problem you should add user for master database with SqlJDBCXAUser permission. or you may execute the following command (also need to grant right first) EXEC sp_addrolemember [SqlJDBCXAUser], 'username'