net.sourceforge.jbizmo.commons.jpa.converter.UUIDStringConverter Maven / Gradle / Ivy
/*
* This file is part of JBizMo, a set of tools, libraries and plug-ins
* for modeling and creating Java-based enterprise applications.
* For more information visit:
*
* http://sourceforge.net/projects/jbizmo/
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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
*/
package net.sourceforge.jbizmo.commons.jpa.converter;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import java.util.UUID;
/**
*
* Converter that is required for mapping fields of type {@link UUID} to a string
*
*
* Copyright 2022 (C) by Martin Ganserer
*
* @author Martin Ganserer
* @version 1.0.0
*/
@Converter
public class UUIDStringConverter implements AttributeConverter {
/*
* (non-Javadoc)
* @see jakarta.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object)
*/
@Override
public String convertToDatabaseColumn(UUID uuid) {
if (uuid == null)
return null;
return uuid.toString();
}
/*
* (non-Javadoc)
* @see jakarta.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object)
*/
@Override
public UUID convertToEntityAttribute(String dbData) {
if (dbData == null)
return null;
return UUID.fromString(dbData);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy