Skip to content

Commit

Permalink
Fix Hibernate 6.6.1.Final issues with .hbm.xml configuration
Browse files Browse the repository at this point in the history
Hibernate 6.6.1 is gradually phasing out XML configuration, and support
for .hbm.xml seems to be encountering regressions. Specifically,
Hibernate mistakenly interprets methods like getRolesAsString() as
entity properties, triggering errors due to the absence of a
corresponding setter.

Attempts to resolve this with @transient were unsuccessful. As a
temporary fix, we've renamed methods like getRolesAsString() to
rolesAsString() to avoid them being treated as bean properties.

We plan to refactor these entities soon, replacing the .hbm.xml
configuration with JPA annotations for better compatibility with
Hibernate 6.x.
  • Loading branch information
ar committed Oct 22, 2024
1 parent d3c2db7 commit e5d4c25
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
5 changes: 4 additions & 1 deletion modules/eeuser/src/main/java/org/jpos/ee/Consumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.*;
import java.io.Serializable;

import jakarta.persistence.Transient;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
Expand Down Expand Up @@ -127,7 +129,8 @@ public void removeRole (Role role) {
public void removeAllRoles () {
roles.clear ();
}
public String getRolesAsString () {
@Transient
public String rolesAsString() {
StringBuilder sb = new StringBuilder();
for (Role r : roles) {
if (!sb.isEmpty())
Expand Down
18 changes: 9 additions & 9 deletions modules/eeuser/src/main/java/org/jpos/ee/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public boolean hasPermission (String permName) {
ignoreRealm = true;
permName = permName.substring(1);
}
return permName != null && (getActivePermissions(ignoreRealm).contains(Permission.valueOf(permName)));
return permName != null && (activePermissions(ignoreRealm).contains(Permission.valueOf(permName)));
}

public void addPermission (String permName) {
Expand Down Expand Up @@ -146,33 +146,33 @@ public String toString() {
* get Fully Qualified Role Name
* @return [realm:]role.name
*/
private String getFQRN() {
private String FQRN() {
return getRealm () != null ? String.format("%s:role.%s", getRealm().getName(), getName()) :
String.format("role.%s", getName());
}

public Set<Permission> getActivePermissions () {
return getActivePermissions(false);
public Set<Permission> activePermissions() {
return activePermissions(false);
}

public Set<Permission> getActivePermissions (boolean ignoreRealm) {
public Set<Permission> activePermissions(boolean ignoreRealm) {
Set<Permission> perm = new LinkedHashSet<>();
perm.add(Permission.valueOf(getFQRN()));
perm.add(Permission.valueOf(FQRN()));
if (ignoreRealm)
perm.addAll(permissions);
else
perm.addAll(getActivePermissions(getRealm()));
perm.addAll(activePermissions(getRealm()));
for (Role r = this; r.getParent() != null; ) {
r = r.getParent();
if (ignoreRealm)
perm.addAll(r.getPermissions());
else
perm.addAll(r.getActivePermissions(getRealm()));
perm.addAll(r.activePermissions(getRealm()));
}
return perm;
}

private Set<Permission> getActivePermissions (Realm r) {
private Set<Permission> activePermissions(Realm r) {
return r != null ?
permissions.stream().map(
p -> Permission.valueOf(r.getName() + ":" + p.getName())
Expand Down
6 changes: 3 additions & 3 deletions modules/eeuser/src/main/java/org/jpos/ee/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void removeRole (Role role) {
public void removeAllRoles () {
roles.clear ();
}
public String getRolesAsString () {
public String rolesAsString() {
StringBuilder sb = new StringBuilder();
for (Role r : roles) {
if (!sb.isEmpty())
Expand All @@ -197,7 +197,7 @@ public String getRolesAsString () {
}
return sb.toString();
}
public String getRealmsAsString () {
public String realmsAsString() {
StringBuilder sb = new StringBuilder();
for (Role r : roles) {
if (r.getRealm() != null) {
Expand Down Expand Up @@ -261,7 +261,7 @@ public int hashCode() {
/**
* @return nick(id)
*/
public String getNickAndId() {
public String nickAndId() {
StringBuilder sb = new StringBuilder (getNick());
sb.append ('(');
sb.append (getId());
Expand Down
2 changes: 1 addition & 1 deletion modules/eeuser/src/main/java/org/jpos/q2/cli/ADDUSER.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void exec(CLIContext cli, String[] args) throws Exception {
Collections.addAll(user.getRoles(), rr);
user.setActive(true);
db.commit();
cli.println ("User '" + user.getNickAndId() + "' created");
cli.println ("User '" + user.nickAndId() + "' created");
} catch (Exception e) {
cli.println (e.getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion modules/eeuser/src/main/java/org/jpos/q2/cli/PASSWD.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void exec(CLIContext cli, String[] args) throws Exception {
mgr.setPassword(user, line.getOptionValue('p'));
db.session().persist(user);
db.commit();
cli.println ("User '" + user.getNickAndId() + "': password changed.");
cli.println ("User '" + user.nickAndId() + "': password changed.");
} catch (Exception e) {
cli.println (e.getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion modules/eeuser/src/main/java/org/jpos/q2/cli/RMUSER.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void exec(CLIContext cli, String[] args) throws Exception {
u.setDeleted(true);
}
db.commit();
cli.println(u != null ? "User " + u.getNickAndId() + " has been deleted" : "User does not exist");
cli.println(u != null ? "User " + u.nickAndId() + " has been deleted" : "User does not exist");
} catch (Exception e) {
cli.println(e.getMessage());
}
Expand Down

0 comments on commit e5d4c25

Please sign in to comment.