[Security & JAAS/JBoss] - Problem with JAAS and Declarative Security on JBOSS 4.2.1 GA
by fakhreldeen
Hello,
I am trying to implement an integration between Declarative Security and JAAS on JBOSS 4.2.1 GA. I have specified in my web.xml file that all jsp files under the directory called "security" are protected and only accessible by the role "Admin". I also specified in the web.xml file that Authentication is done by Login FORM. I then created a configuration for the DatabaseSeverLoginModule in login-config.xml, and created a servlet that uses the LoginContext to authorize the user. The Login page's form's action points to this servlet rather than j_security_check. However, it doesn't seem to work, because I can't access the secure pages, even though I enter the correct username and password. Here are my files:
*****web.xml*****
| <servlet>
| <servlet-name>loginservlet</servlet-name>
| <servlet-class>loginservlet</servlet-class>
| </servlet>
| <servlet-mapping>
| <servlet-name>loginservlet</servlet-name>
| <url-pattern>/loginservlet</url-pattern>
| </servlet-mapping>
| <session-config>
| <session-timeout>
| 30
| </session-timeout>
| </session-config>
| <welcome-file-list>
| <welcome-file>index.jsp</welcome-file>
| </welcome-file-list>
| <security-constraint>
| <display-name>Constraint1</display-name>
| <web-resource-collection>
| <web-resource-name>Secure Pages</web-resource-name>
| <description>Secure Pages</description>
| <url-pattern>/security/*</url-pattern>
| <http-method>GET</http-method>
| <http-method>POST</http-method>
| <http-method>HEAD</http-method>
| <http-method>PUT</http-method>
| <http-method>OPTIONS</http-method>
| <http-method>TRACE</http-method>
| <http-method>DELETE</http-method>
| </web-resource-collection>
| <auth-constraint>
| <description>Admin</description>
| <role-name>Admin</role-name>
| </auth-constraint>
| </security-constraint>
| <login-config>
| <auth-method>FORM</auth-method>
| <realm-name>Test Realm</realm-name>
| <form-login-config>
| <form-login-page>/Login.jsp</form-login-page>
| <form-error-page>/Error.jsp</form-error-page>
| </form-login-config>
| </login-config>
| <security-role>
| <description>Admin User
| </description>
| <role-name>Admin</role-name>
| </security-role>
| </web-app>
*****login-conf.xml*****
<application-policy name = "testDB">
| <authentication>
| <login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"
| flag = "required">
| <module-option name = "unauthenticatedIdentity">guest</module-option>
| <module-option name = "dsJndiName">java:/testDB</module-option>
| <module-option name = "principalsQuery">SELECT password from Principals where PrincipalID =?</module-option>
| <module-option name = "rolesQuery">SELECT Role, Rolegroup FROM roles WHERE principalid=?</module-option>
| </login-module>
| </authentication>
| </application-policy>
****jboss-web.xml****
<jboss-web>
| <security-domain>java:/jaas/testDB</security-domain>
| <context-root>/testJBOSSsecurity</context-root>
| </jboss-web>
****Login.jsp*****
<FORM name="logonForm" action="loginservlet" METHOD="POST">
| <TABLE width="100%" border="0" cellspacing="0" cellpadding=
| "1" bgcolor="white">
| <TABLE width="100%" border="0" cellspacing=
| "0" cellpadding="5">
| <TR align="center">
| <TD align="right" class="Prompt"></TD>
| <TD align="left">
| <INPUT type="text" name="j_username" maxlength=20>
| </TD>
| </TR>
| <TR align="center">
| <TD align="right" class="Prompt"> </TD>
| <TD align="left">
| <INPUT type="password"
| name="j_password" maxlength=20 >
| <BR>
| <TR align="center">
| <TD align="right" class="Prompt"> </TD>
| <TD align="left">
| <input type="submit" value="Login">
****loginservlet.java*****
try {
| SecurityAssociationHandler handler = new
| SecurityAssociationHandler();
| Principal user = new SimplePrincipal(request.getParameter("j_username"));
| handler.setSecurityInfo(user, request.getParameter("j_password"));
| LoginContext loginContext = new LoginContext("testDB",(CallbackHandler)handler);
| loginContext.login();
| Subject subject = loginContext.getSubject();
| Set principals = subject.getPrincipals();
| principals.add(user);
| out.println(subject.toString());
| //response.sendRedirect("securepage.java");
| }
So, those are my files.....In the database, I have two tables, one table called Principals and that has the username semsem and password password1, and the other table is called roles, which has principleid = semsem, role = Admin, and rolegroup = AdminGroup. What I am trying to do, is integrate JAAS and Declarative Security, so that I don't have to programatically declare which pages are accessed by which type of user. However, When I reach the Login Form and enter the correct username and password, nothing happens, which means that after I enter the correct username and password, I am presented with the login form again....I can verify that the servlet code is correct, because I can directly visit the login page with out trying to access it by requesting a secure page, and I enter the correct username and password, and I get a print line of the subject's principals as they are in the database from the line out.println(subject.toString());, that print out is: Subject: Principal: semsem Principal: Admin(members:Admin)
Your help is very appreciated
Thank You
Sam
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148602#4148602
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4148602
17 years, 11 months
[EJB 3.0] - Re: Why is Remote Interface not installed
by jaikiran
Markus,
Let's stick to JBoss-4.0.4 (i guess the book is based on that?). And let's stick to JDK-1.5 in all places (the client and the server).
anonymous wrote : Caused by: java.io.InvalidClassException: org.jboss.ejb3.remoting.IsLocalInterceptor; local class in
| compatible: stream classdesc serialVersionUID = 595045557897063404, local class serialVersionUID = -
| 3758782076801249473
The exception that you are seeing is because of an incorrect version of jar file in your client classpath. Remove all the jar files from your client classpath and then include only the jbossall-client.jar which is present in the %JBOSS_HOME%\client folder of your JBoss-4.0.4 version of the server. Then rebuild your entire project with JDK 1.5 and deploy it to the server. Let us know how it goes.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148601#4148601
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4148601
17 years, 11 months
[EJB 3.0] - Re: JBossAS4.2.x JPA annatations on Oracle92 xmlType column
by cd_eat
Really busi these days, now I post my way:
1. make an extention dialect of hibernate, and add it to the jboss server's library path (jboss-4.2.x\server\default\lib\ for example)
2. mapping the oracle xml column to a jpa bean field using the class type we defined above.
3. modify a jboss java source file (in jar file: jboss-4.2.x\server\default\lib\jboss-common-jdbc-wrapper.jar)
org.jboss.resource.adapter.jdbc.WrappedConnection to expose a sql connection.
4. notice: you must use the oci driver instead of the thin driver of oracle9i, since the're bugs in thin dirver which cause sending large xml content will faild( larger than 25KB maybe)
5. After all this, we can integrate oracle xml feature (xmlType column) with jpa beans.
6. More importent, I don't think u want to do this-_-. Oracle9i/10g xmlType is really slow(by store as clob), I made comparison between oracle9i and db2 9.5 by inserting 10,000 2KB xml records and then quering one using xpathes. result is that:
------------------Inserting speed--------Quering time(get 1 out of 10,000)
Oracle-------------14/s --------------------24s
DB2v95------------55/s-------------------0.6s
here are the source codes:
1:OracleXMLTypes
import java.io.Serializable;
| import java.sql.Connection;
| import java.sql.PreparedStatement;
| import java.sql.ResultSet;
| import java.sql.SQLException;
|
| import oracle.jdbc.driver.OracleResultSet;
| import oracle.sql.OPAQUE;
| import oracle.xdb.XMLType;
|
| import org.hibernate.HibernateException;
| import org.hibernate.usertype.UserType;
| import org.jboss.resource.adapter.jdbc.WrappedConnection;
|
| public class OracleXMLTypes implements UserType, Serializable{
| private static final Class returnedClass = String.class;
| private static final int[] SQL_TYPES = new int[] { oracle.xdb.XMLType._SQL_TYPECODE };
| public String xmlContent;
|
| public OracleXMLTypes(){
|
| }
| public OracleXMLTypes(String xmlContent){
| this.xmlContent = xmlContent;
| }
|
| public int[] sqlTypes() {
| return SQL_TYPES;
| }
|
| public Class returnedClass() {
| return returnedClass;
|
| }
|
| public boolean equals(Object arg0, Object arg1) throws HibernateException {
| if (arg0 == null || arg1 == null) {
| throw new HibernateException("None of the arguments can be null.");
| }
|
| if (arg0 instanceof oracle.xdb.XMLType
| && arg1 instanceof oracle.xdb.XMLType) {
|
| return arg0.equals(arg1);
| }
| return false;
|
| }
|
| public int hashCode(Object arg0) throws HibernateException {
| return arg0.hashCode();
| }
|
| public Object nullSafeGet(ResultSet rs, String[] names, Object arg2)
| throws HibernateException, SQLException {
| XMLType xt = (XMLType)rs.getObject(names[0]);
| return new OracleXMLTypes(xt.getStringVal());
| }
|
| public void nullSafeSet(PreparedStatement ps, Object value, int index)
| throws HibernateException, SQLException {
| WrappedConnection wc = (WrappedConnection)ps.getConnection();
| XMLType xmlType = XMLType.createXML(wc.oriSQLConnection(), ((OracleXMLTypes)value).xmlContent);
| ps.setObject(index, xmlType);
| }
|
| public Object deepCopy(Object value) throws HibernateException {
| //
| return value;
| }
|
| public boolean isMutable() {
| return false;
| }
|
| public Serializable disassemble(Object arg0) throws HibernateException {
| return null;
| }
|
| public Object assemble(Serializable arg0, Object arg1)
| throws HibernateException {
| return null;
| }
|
| public Object replace(Object arg0, Object arg1, Object arg2)
| throws HibernateException {
| return null;
| }
|
| }
2: jboss java src:WrappedConnection
/*
| * JBoss, Home of Professional Open Source.
| * Copyright 2006, Red Hat Middleware LLC, and individual contributors
| * as indicated by the @author tags. See the copyright.txt file in the
| * distribution for a full listing of individual contributors.
| *
| * This is free software; you can redistribute it and/or modify it
| * under the terms of the GNU Lesser General Public License as
| * published by the Free Software Foundation; either version 2.1 of
| * the License, or (at your option) any later version.
| *
| * This software is distributed in the hope that it will be useful,
| * but WITHOUT ANY WARRANTY; without even the implied warranty of
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
| * Lesser General Public License for more details.
| *
| * You should have received a copy of the GNU Lesser General Public
| * License along with this software; if not, write to the Free
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
| */
| package org.jboss.resource.adapter.jdbc;
|
| import java.sql.CallableStatement;
| import java.sql.Connection;
| import java.sql.DatabaseMetaData;
| import java.sql.PreparedStatement;
| import java.sql.ResultSet;
| import java.sql.SQLException;
| import java.sql.SQLWarning;
| import java.sql.Savepoint;
| import java.sql.Statement;
| import java.util.HashMap;
| import java.util.Iterator;
| import java.util.Map;
|
| import org.jboss.logging.Logger;
| import org.jboss.util.NestedSQLException;
|
| /**
| * A wrapper for a connection.
| *
| * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
| * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
| * @version $Revision: 57189 $
| */
| public class WrappedConnection implements Connection
| {
| private static final Logger log = Logger.getLogger(WrappedConnection.class);
|
| private BaseWrapperManagedConnection mc;
|
| private WrapperDataSource dataSource;
|
| private HashMap statements;
|
| private boolean closed = false;
|
| private int trackStatements;
|
|
| // here we must expose a sql conn, which used by the 'OracleXMLTypes' we defined
| public Connection oriSQLConnection(){
| return mc.con;
| }
|
| public WrappedConnection(final BaseWrapperManagedConnection mc)
| {
| this.mc = mc;
| if (mc != null)
| trackStatements = mc.getTrackStatements();
| }
|
| void setManagedConnection(final BaseWrapperManagedConnection mc)
| {
| this.mc = mc;
| if (mc != null)
| trackStatements = mc.getTrackStatements();
| }
|
| public WrapperDataSource getDataSource()
| {
| return dataSource;
| }
|
| protected void setDataSource(WrapperDataSource dataSource)
| {
| this.dataSource = dataSource;
| }
|
| public void setReadOnly(boolean readOnly) throws SQLException
| {
| checkStatus();
| mc.setJdbcReadOnly(readOnly);
| }
|
| public boolean isReadOnly() throws SQLException
| {
| checkStatus();
| return mc.isJdbcReadOnly();
| }
|
| public void close() throws SQLException
| {
| closed = true;
| if (mc != null)
| {
| if (trackStatements != BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
| {
| synchronized (this)
| {
| if (statements != null)
| {
| for (Iterator i = statements.entrySet().iterator(); i.hasNext(); )
| {
| Map.Entry entry = (Map.Entry) i.next();
| WrappedStatement ws = (WrappedStatement) entry.getKey();
| if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_TRUE_INT)
| {
| Throwable stackTrace = (Throwable) entry.getValue();
| log.warn("Closing a statement you left open, please do your own housekeeping", stackTrace);
| }
| try
| {
| ws.internalClose();
| }
| catch (Throwable t)
| {
| log.warn("Exception trying to close statement:", t);
| }
| }
| }
| }
| }
| mc.closeHandle(this);
| }
| mc = null;
| dataSource = null;
| }
|
| public boolean isClosed() throws SQLException
| {
| return closed;
| }
|
| public Statement createStatement() throws SQLException
| {
| checkTransaction();
| try
| {
| return new WrappedStatement(this, mc.getConnection().createStatement());
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
| {
| checkTransaction();
| try
| {
| return new WrappedStatement(this, mc.getConnection().createStatement(resultSetType, resultSetConcurrency));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
| throws SQLException
| {
|
| checkTransaction();
| try
| {
| return new WrappedStatement(this, mc.getConnection()
| .createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public PreparedStatement prepareStatement(String sql) throws SQLException
| {
| checkTransaction();
| try
| {
| return new WrappedPreparedStatement(this, mc.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
| throws SQLException
| {
| checkTransaction();
| try
| {
| return new WrappedPreparedStatement(this, mc.prepareStatement(sql, resultSetType, resultSetConcurrency));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
| int resultSetHoldability) throws SQLException
| {
| checkTransaction();
| try
| {
| return new WrappedPreparedStatement(this, mc.getConnection()
| .prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
| {
| checkTransaction();
| try
| {
| return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, autoGeneratedKeys));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
| {
| checkTransaction();
| try
| {
| return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, columnIndexes));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
| {
|
| checkTransaction();
| try
| {
| return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, columnNames));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public CallableStatement prepareCall(String sql) throws SQLException
| {
| checkTransaction();
| try
| {
| return new WrappedCallableStatement(this, mc.prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
| {
| checkTransaction();
| try
| {
| return new WrappedCallableStatement(this, mc.prepareCall(sql, resultSetType, resultSetConcurrency));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
| int resultSetHoldability) throws SQLException
| {
|
| checkTransaction();
| try
| {
| return new WrappedCallableStatement(this, mc.getConnection()
| .prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public String nativeSQL(String sql) throws SQLException
| {
| checkTransaction();
| try
| {
| return mc.getConnection().nativeSQL(sql);
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public void setAutoCommit(boolean autocommit) throws SQLException
| {
| checkStatus();
| mc.setJdbcAutoCommit(autocommit);
| }
|
| public boolean getAutoCommit() throws SQLException
| {
| checkStatus();
| return mc.isJdbcAutoCommit();
| }
|
| public void commit() throws SQLException
| {
| checkTransaction();
| mc.jdbcCommit();
| }
|
| public void rollback() throws SQLException
| {
| checkTransaction();
| mc.jdbcRollback();
| }
|
| public void rollback(Savepoint savepoint) throws SQLException
| {
| checkTransaction();
| mc.jdbcRollback(savepoint);
| }
|
| public DatabaseMetaData getMetaData() throws SQLException
| {
| checkTransaction();
| try
| {
| return mc.getConnection().getMetaData();
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public void setCatalog(String catalog) throws SQLException
| {
| checkTransaction();
| try
| {
| mc.getConnection().setCatalog(catalog);
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
| public String getCatalog() throws SQLException
| {
| checkTransaction();
| try
| {
| return mc.getConnection().getCatalog();
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public void setTransactionIsolation(int isolationLevel) throws SQLException
| {
| checkStatus();
| mc.setJdbcTransactionIsolation(isolationLevel);
| }
|
| public int getTransactionIsolation() throws SQLException
| {
| checkStatus();
| return mc.getJdbcTransactionIsolation();
| }
|
| public SQLWarning getWarnings() throws SQLException
| {
| checkTransaction();
| try
| {
| return mc.getConnection().getWarnings();
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public void clearWarnings() throws SQLException
| {
| checkTransaction();
| try
| {
| mc.getConnection().clearWarnings();
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public Map getTypeMap() throws SQLException
| {
| checkTransaction();
| try
| {
| return mc.getConnection().getTypeMap();
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public void setTypeMap(Map typeMap) throws SQLException
| {
| checkTransaction();
| try
| {
| mc.getConnection().setTypeMap(typeMap);
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public void setHoldability(int holdability) throws SQLException
| {
| checkTransaction();
| try
| {
| mc.getConnection().setHoldability(holdability);
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public int getHoldability() throws SQLException
| {
| checkTransaction();
| try
| {
| return mc.getConnection().getHoldability();
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public Savepoint setSavepoint() throws SQLException
| {
| checkTransaction();
| try
| {
| return mc.getConnection().setSavepoint();
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public Savepoint setSavepoint(String name) throws SQLException
| {
| checkTransaction();
| try
| {
| return mc.getConnection().setSavepoint(name);
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public void releaseSavepoint(Savepoint savepoint) throws SQLException
| {
| checkTransaction();
| try
| {
| mc.getConnection().releaseSavepoint(savepoint);
| }
| catch (Throwable t)
| {
| throw checkException(t);
| }
| }
|
| public Connection getUnderlyingConnection() throws SQLException
| {
| checkTransaction();
| return mc.getConnection();
| }
|
| void checkTransaction() throws SQLException
| {
| checkStatus();
| mc.checkTransaction();
| }
|
| /**
| * The checkStatus method checks that the handle has not been closed and
| * that it is associated with a managed connection.
| *
| * @exception SQLException if an error occurs
| */
| protected void checkStatus() throws SQLException
| {
| if (closed)
| throw new SQLException("Connection handle has been closed and is unusable");
| if (mc == null)
| throw new SQLException("Connection handle is not currently associated with a ManagedConnection");
| }
|
| /**
| * The base checkException method rethrows the supplied exception, informing
| * the ManagedConnection of the error. Subclasses may override this to
| * filter exceptions based on their severity.
| *
| * @param e a <code>SQLException</code> value
| * @exception Exception if an error occurs
| */
| protected SQLException checkException(Throwable t) throws SQLException
| {
| if (mc != null)
| mc.connectionError(t);
| if (t instanceof SQLException)
| throw (SQLException) t;
| else
| throw new NestedSQLException("Error", t);
| }
|
| int getTrackStatements()
| {
| return trackStatements;
| }
|
| void registerStatement(WrappedStatement ws)
| {
| if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
| return;
|
| synchronized (this)
| {
| if (statements == null)
| statements = new HashMap();
|
| if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_TRUE_INT)
| statements.put(ws, new Throwable("STACKTRACE"));
| else
| statements.put(ws, null);
| }
| }
|
| void unregisterStatement(WrappedStatement ws)
| {
| if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
| return;
| synchronized (this)
| {
| if (statements != null)
| statements.remove(ws);
| }
| }
|
| void checkConfiguredQueryTimeout(WrappedStatement ws) throws SQLException
| {
| if (mc == null || dataSource == null)
| return;
|
| int timeout = 0;
|
| // Use the transaction timeout
| if (mc.isTransactionQueryTimeout())
| timeout = dataSource.getTimeLeftBeforeTransactionTimeout();
|
| // Look for a configured value
| if (timeout <= 0)
| timeout = mc.getQueryTimeout();
|
| if (timeout > 0)
| ws.setQueryTimeout(timeout);
| }
|
| Logger getLogger()
| {
| return log;
| }
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148599#4148599
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4148599
17 years, 11 months
[Persistence, JBoss/CMP, Hibernate, Database] - Problems after upgrading to 4.2.2 with MySQL and BLOB
by C-Box
Hi,
we just upgraded our JBoss from 4.0.2 to 4.2.2.
Our MySQL is 5.0.51a --> all tables are INNODB because of transactions.
Within our database we do have a table that has two BLOB fields inside holding some binaries (one is a JRXML-file = JasperReportDesign-Object and one is the compiled design as as so called JASPER-file = JasperReport-Object) and some other fields (varchar and integer).
'ID', 'int(11)', 'NO', 'PRI', '', ''
| 'Bezeichnung', 'varchar(100)', 'YES', '', '', ''
| 'Design', 'longblob', 'YES', '', '', ''
| 'Report', 'longblob', 'YES', '', '', ''
| 'BusinessObjectID', 'int(11)', 'YES', '', '', ''
| 'ReportTyp', 'int(11)', 'YES', '', '', ''
| 'AfpsLockID', 'int(11)', 'YES', '', '', ''
| 'AfpsVersion', 'int(11)', 'YES', '', '', ''
|
We do use CMP logic.
The TypeMapping within standardjbosscmp.xml hasn't changed from 4.0.2 to 4.2.2 for the MySQL mapping:
for BLOB we always use:
<mapping>
| <java-type>java.lang.Object</java-type>
| <jdbc-type>BLOB</jdbc-type>
| <sql-type>LONGBLOB</sql-type>
| </mapping>
When I want to change one record within that table I get an exception, that says that the getInt method of the ResultSetImpl can't get an int from a field. I already created my own finder "findById" to not use the standard builtin findByPrimaryKey finder --> but without success - same error:
here is the finder:
| <query>
| <query-method>
| <method-name>findById</method-name>
| <method-params>
| <method-param>java.lang.Integer</method-param>
| </method-params>
| </query-method>
| <ejb-ql>SELECT OBJECT(o) FROM DruckVorlageReport AS o WHERE o.id = ?1</ejb-ql>
| </query>
and here the exception:
|
| 2008-05-05 10:25:47,104 ERROR [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.DruckVorlageReport#findById] Find failed
| javax.ejb.EJBException: Internal error getting results for field member businessObjectID
| at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.loadArgumentResults(JDBCAbstractCMPFieldBridge.java:498)
| at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.loadArgumentResults(JDBCAbstractCMPFieldBridge.java:432)
| at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQueryCommand$EagerCollectionFactory.createCollection(JDBCAbstractQueryCommand.java:765)
| at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQueryCommand.execute(JDBCAbstractQueryCommand.java:265)
| at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQueryCommand.execute(JDBCAbstractQueryCommand.java:144)
| at org.jboss.ejb.plugins.cmp.jdbc.JDBCFindEntityCommand.execute(JDBCFindEntityCommand.java:61)
| at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.findEntity(JDBCStoreManager.java:604)
| at org.jboss.ejb.plugins.CMPPersistenceManager.findEntity(CMPPersistenceManager.java:315)
| at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.findEntity(CachedConnectionInterceptor.java:236)
| at org.jboss.ejb.EntityContainer.findSingleObject(EntityContainer.java:1099)
| at org.jboss.ejb.EntityContainer.findLocal(EntityContainer.java:676)
| ....
|
|
| Caused by: java.sql.SQLException: Invalid value for getInt() - ' <?xml version="1.0" encoding="UTF-8"?>
|
| ... here the whole content of the column "design" is shown what is the JRXML file stored in the BLOB column "design"
| ....
|
| at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
| at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
| at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
| at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2709)
the select statement that JBoss use seems to be okay:
2008-05-05 10:25:47,089 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.DruckVorlageReport#findById] Executing SQL: SELECT t0_o.ID, t0_o.Bezeichnung, t0_o.Design, t0_o.Report, t0_o.BusinessObjectID, t0_o.ReportTyp, t0_o.AfpsVersion, t0_o.AfpsLockID FROM druckvorlagereport t0_o WHERE (t0_o.ID = ?)
I already updated the mysql-driver to mysql-connector-java-5.1.6-bin.jar but without success.
Has anybody a glue what's going wrong?
If I use direct sql code with the connection to get a resultset it works like a charm, so I guess it can't be a driver problem.
Seems that JBoss trys to convert my blob field into an int to find the record... but why????
When I debug, I can see, that up to the call of the finder all arguments are correct (so no wrong input).
Would be nice to get some response.
regards from Germany
Christian
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148593#4148593
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4148593
17 years, 11 months