When I ran a query (javax.persistence.Query) to check the existence of a record I got:
22:06:12,026 ERROR [org.jboss.ejb3.tx2.impl.CMTTxInterceptor] javax.ejb.EJBTransactionRolledbackException: No entity found for query
As described in this thread getSigleResult() if there isn't any record to fetch throws a NoResultException.
Use instead getResultList()
venerdì 25 novembre 2011
MySql and case sensitive in where clause
By default the content of a VARCHAR field in MySql is not case sensitive in string searches.
This official article gives some solutions if you need distinguish between "hello" and "Hello".
In my case I have a table with a string field computed starting from the auto-incremental numeric id.
This alias (unique) is stored for performance reasons and uses a set of 62 symbols (A-Za-z0-9).
It is a base-62 representation of the real id so of course, the alias "xa" is different from "xA".
My first table definition was:
CREATE TABLE IF NOT EXISTS `boxes` (
`idboxes` int(11) unsigned NOT NULL AUTO_INCREMENT,
`creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`alias` varchar(45) NOT NULL,
`language` varchar(45) DEFAULT NULL,
`lastvisit` timestamp NULL DEFAULT NULL,
`readonly` int(11) DEFAULT NULL,
`password` varchar(60) DEFAULT '',
PRIMARY KEY (`idboxes`),
KEY `aliasIndex` (`alias`)
)
That with this query returned the following records:
select * from boxes where alias='xi'
'320', '2011-11-25 14:22:26', 'xI', 'text/x-java', NULL, '0', '123'
Since alias must be an unique id this is a BIG problem!
The solution is to set the field collation to one case sensitive charset (or to a binary). You can identify them from the suffix "_cs" (or _bi).
In my case cp1251_general_cs is enough good because it contains all my 62 symbols set.
So the table can be changed in this way:
CREATE TABLE IF NOT EXISTS `boxes` (
`idboxes` int(11) unsigned NOT NULL AUTO_INCREMENT,
`creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`alias` varchar(45) CHARACTER SET cp1251 COLLATE cp1251_general_cs NOT NULL,
`language` varchar(45) DEFAULT NULL,
`lastvisit` timestamp NULL DEFAULT NULL,
`readonly` int(11) DEFAULT NULL,
`password` varchar(60) DEFAULT '',
PRIMARY KEY (`idboxes`),
KEY `aliasIndex` (`alias`)
)
The same change have to be applied to the password field!
This official article gives some solutions if you need distinguish between "hello" and "Hello".
In my case I have a table with a string field computed starting from the auto-incremental numeric id.
This alias (unique) is stored for performance reasons and uses a set of 62 symbols (A-Za-z0-9).
It is a base-62 representation of the real id so of course, the alias "xa" is different from "xA".
My first table definition was:
CREATE TABLE IF NOT EXISTS `boxes` (
`idboxes` int(11) unsigned NOT NULL AUTO_INCREMENT,
`creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`alias` varchar(45) NOT NULL,
`language` varchar(45) DEFAULT NULL,
`lastvisit` timestamp NULL DEFAULT NULL,
`readonly` int(11) DEFAULT NULL,
`password` varchar(60) DEFAULT '',
PRIMARY KEY (`idboxes`),
KEY `aliasIndex` (`alias`)
)
That with this query returned the following records:
select * from boxes where alias='xi'
'320', '2011-11-25 14:22:26', 'xI', 'text/x-java', NULL, '0', '123'
'317', '2011-11-16 17:19:30', 'xi', 'text/plain', NULL, '0', 'pwd'
Since alias must be an unique id this is a BIG problem!
The solution is to set the field collation to one case sensitive charset (or to a binary). You can identify them from the suffix "_cs" (or _bi).
In my case cp1251_general_cs is enough good because it contains all my 62 symbols set.
So the table can be changed in this way:
CREATE TABLE IF NOT EXISTS `boxes` (
`idboxes` int(11) unsigned NOT NULL AUTO_INCREMENT,
`creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`alias` varchar(45) CHARACTER SET cp1251 COLLATE cp1251_general_cs NOT NULL,
`language` varchar(45) DEFAULT NULL,
`lastvisit` timestamp NULL DEFAULT NULL,
`readonly` int(11) DEFAULT NULL,
`password` varchar(60) DEFAULT '',
PRIMARY KEY (`idboxes`),
KEY `aliasIndex` (`alias`)
)
The same change have to be applied to the password field!
martedì 8 novembre 2011
Creating a new MySQL DS
Create a file in the deploy directory (eg. mysql-ds.xml) with a content like this:
<datasources>
<local-tx-datasource>
<jndi-name>SourceBoxDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/sourcebox</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password></password>
</local-tx-datasource>
</datasources>
If JBossAS is running, in the console you will get:
In order to use it in the entities definition you can set in the persistence.xml file this property:
<datasources>
<local-tx-datasource>
<jndi-name>SourceBoxDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/sourcebox</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password></password>
</local-tx-datasource>
</datasources>
If JBossAS is running, in the console you will get:
15:17:06,859 INFO [org.jboss.resource.connectionmanager.ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=SourceBoxDS' to JNDI name 'java:SourceBoxDS'It's clear from this log that now the db object is mapped in JNDI to the path "java:SourceBoxDS".
In order to use it in the entities definition you can set in the persistence.xml file this property:
<jta-data-source>java:SourceBoxDS</jta-data-source>
Error in deployment
ERROR: Using the standard deployment precedure with JBossTools I got an error because of a locked file that can not be overwritten.
SOLUTION: Deploy as compressed archive changing the setup in the server configuration.
Error renaming C:\Users\Tiziano\Desktop\Progetti\.metadata\.plugins\org.jboss.ide.eclipse.as.core\JBoss_6.x_Runtime_Server1320242844193\tempDeploy\tmp4708729525866439817.jar to C:\Users\Tiziano\Desktop\Progetti\.metadata\.plugins\org.jboss.ide.eclipse.as.core\JBoss_6.x_Runtime_Server1320242844193\deploy\SourceBoxEAR.ear\lib\SourceBoxEntities.jar.This may be caused by your server's temporary deploy directory being on a different filesystem than the final destination.You may adjust these settings in the server editor.
lunedì 7 novembre 2011
Statement Regarding Security Threat to JBoss Application Server
Red Hat has become aware of a worm currently affecting unpatched or unsecured servers running JBoss Application Server and products based on it.
http://community.jboss.org/blogs/mjc/2011/10/20/statement-regarding-security-threat-to-jboss-application-server
http://community.jboss.org/blogs/mjc/2011/10/20/statement-regarding-security-threat-to-jboss-application-server
mercoledì 2 novembre 2011
Eclipse - Missing lib in autogenerated EJB3 Client Project
If you use the eclipse wizard for creating an EJB Project, you have seen that a referenced project called "<name>Client" is created.
It contains the interfaces for local and remote access, but for some reason the EE libraries are not in the build path.
Right click on the client project and add the EE libraries:
-------------------------------------------------------------------------------------------------
Iscriviti a:
Commenti (Atom)
